2

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()
이준혁
  • 267
  • 4
  • 14

2 Answers2

2

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:

JosephKumarMichael
  • 971
  • 1
  • 7
  • 9
0


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"
]
}
Suyash Gaur
  • 2,481
  • 2
  • 9
  • 22
  • well...I changed my code like this to receive 'payload' and edited my question. in that code, message appears to be none. thanks in advance @Suyash Gaur – 이준혁 Apr 06 '22 at 23:43