send direct message to slack user from a app bot but not in app channel

江枫思渺然 提交于 2020-01-30 10:34:06

问题


Is there a way to send direct message to from a bot(myapp/user) to a user say xyz or to a user's slackbot. The message needs to appear against the user and not on the mybot app. I am using the python slack-client.

Using below code to send the message:

user_id="<touser>"
im_channel=self.open_dm(user_id)
slack_client.api_call("chat.postMessage",channel=im_channel,text="hi buddy", as_user=True)

The above code posts the message in the myapp app channel. Is there a way for the bot to send the message directly to the user and not in the app channel?

OR

Is there a way for the myapp bot to send to slackbot channel addressing the user?


回答1:


Yes.

Just send a message with the user ID for channel and it will appear in the slackbot channel of that user.

Something like this:

user_id="<touser>"
slack_client.api_call("chat.postMessage",channel=user_id,text="hi buddy")

However, note that every message on Slack must to use a channel that includes so called "direct messages". That is how Slack works.



来源:https://stackoverflow.com/questions/53759484/send-direct-message-to-slack-user-from-a-app-bot-but-not-in-app-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!