简体   繁体   中英

is there any way to send message to thread in slack bolt?

I am trying to do this tutorial in python.
https://api.slack.com/tutorials/tracks/responding-to-app-mentions

However, it only sends to 'channel', not message 'thread' in channel(the message which user mentioned bot).
Also, It does not show how to see mentioned message infos in app(like message string, message_ts, etc..).
Can I see mentioned message and that messages thread_ts?

plus, this is my code in bot, which message appears to be None

@app.event("app_mention")
def event_test(say, message):
    pass
if __name__ == "__main__":
    SocketModeHandler(app, app_token).start()


The payload received from app_mention events contains all the details that you need.
https://api.slack.com/events/app_mention

Example: https://api.slack.com/events/app_mention#app_mention-event__example-event-payloads__standard-app-mention-when-your-app-is-already-in-channel

{
"token": "ZZZZZZWSxiZZZ2yIvs3peJ",
"team_id": "T061EG9R6",
"api_app_id": "A0MDYCDME",
"event": {
    "type": "app_mention",
    "user": "U061F7AUR",
    "text": "What is the hour of the pearl, <@U0LAN0Z89>?",
    "ts": "1515449522.000016",
    "channel": "C0LAN2Q65",
    "event_ts": "1515449522000016"
},
"type": "event_callback",
"event_id": "Ev0LAN670R",
"event_time": 1515449522000016,
"authed_users": [
    "U0LAN0Z89"
]
}

Slack body, event args will have the thread id, so it can be used.

@app.event("app_mention")
def event_test(say, body):
    event = body["event"]
    thread_ts = event.get("thread_ts", None) or event["ts"]
    say(text="Hello", thread_ts=thread_ts) 

if __name__ == "__main__":
    SocketModeHandler(app, app_token).start()

Reference:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM