【问题标题】:How to initiate a Direct Message (Private IM) using the Slack API如何使用 Slack API 发起直接消息(私人 IM)
【发布时间】:2016-09-12 15:02:10
【问题描述】:

使用 Slack API(webhooks、RTM、Web,没关系)是否可以与不存在私人 IM 频道的用户启动 DM/私人频道?

我知道 API 调用 https://api.slack.com/methods/im.list 将向我显示已经打开的私人 IM 频道,但是对于机器人来说这是一个空列表,因为没有真正的用户会向机器人发送 DM。

基本上,我们有一个用户列表,他们需要通过聊天机器人私下通知某些用户,而这些用户之前不太可能对聊天机器人进行 DM,因此私人频道尚不存在。我们如何使用 API 创建该频道?

【问题讨论】:

    标签: slack-api slack


    【解决方案1】:

    好吧,傻瓜,RTFM 只需要我。

    https://api.slack.com/methods/im.open

    This method opens a direct message channel with another member of your Slack team.
    
    Arguments
    
    This method has the URL https://slack.com/api/im.open and follows the Slack Web API calling conventions.
    

    【讨论】:

    • @AlexCohen - slack web api 页面在 cURL 中有一个示例:api.slack.com/web(将实际示例作为评论发布太长)
    • curl -X POST -H 'Authorization: Bearer xoxb-1234-56789abcdefghijklmnop' \ -H 'Content-type: application/json' \ --data '{"channel":"C061EG9SL","text":"I hope the tour went well, Mr. Wonka.","attachments": [{"text":"Who wins the lifetime supply of chocolate?","fallback":"You could be telling the computer exactly what it can do with a lifetime supply of chocolate.","color":"#3AA3E3","attachment_type":"default","callback_id":"select_simple_1234","actions":[{"name":"winners_list","text":"Who should win?","type":"select","data_source":"users"}]}]}' \ https://slack.com/api/chat.postMessage
    • 这个问题已经有好几年了,我换了公司,所以无法具体了解我当时使用的内容
    • 谢谢你的作品!我真的在寻找一个使用松弛令牌的例子。我可以使用它来到达我需要的地方。
    猜你喜欢
    • 1970-01-01
    • 2019-11-04
    • 2015-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    相关资源
    最近更新 更多