向用户发送直接消息

时间:2017-01-02 18:20:39

标签: node.js bots botframework slack

现在,我的机器人听到了一个叫做“团队”的闲聊频道。并在该频道回复。我希望它通过直接消息回复用户(例如' User1')。如何构建消息来做到这一点?

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以按如下方式发送直接消息:

    var response = await activityContext.ConnectorAPI.Conversations.CreateDirectConversationAsync(activity.Recipient, activity.From);

    var reply = activity.CreateReply($"This is a direct message to {activity.From.Name ?? activity.From.Id} : {activity.Text}");
    reply.Conversation = new ConversationAccount(id: response.Id);
    reply.ReplyToId = null;

    await activityContext.ConnectorAPI.Conversations.SendToConversationAsync(reply);