简体   繁体   中英

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

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?

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.

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