用户离线时如何启动从Bot到Skype for Business的出站邮件

时间:2019-02-19 09:27:13

标签: c# botframework skype-for-business

根据onetwo,我发现可以向用户发送主动消息。但是,当用户离线时,它似乎不起作用。有可能吗?

我正在使用C#和bot框架V3。

我有2个问题:

  1. 即使用户不在线也可以向用户发送消息

  2. 如果我使用下面的代码(是两个代码),是否可以启动对话框?如果是,怎么办?

我的代码如下

public class CustomWebAPIController : ApiController
{
    [HttpPost]

    [Route("api/CustomWebAPI")]
    public async Task<HttpResponseMessage> SendMessage([FromBody]string userobj)
    {
        try
        {

            //Initiate a Conversation
            string trustServiceUri = "https://api.skypeforbusiness.com/platformservice/botframework";
            MicrosoftAppCredentials.TrustServiceUrl(trustServiceUri);
            ConnectorClient connector = new ConnectorClient(new Uri(trustServiceUri));
            List<ChannelAccount> participants = new List<ChannelAccount>();
            participants.Add(new ChannelAccount("sip:XXXXX@XXXXX.onmicrosoft.com", "Agent"));
            ConversationParameters parameters = new ConversationParameters(true, new ChannelAccount("sip:XXXXXbot@XXXXX.onmicrosoft.com", "Bot"), participants, "TestTopic");
            ConversationResourceResponse response = connector.Conversations.CreateConversationAsync(parameters).Result;

            //Initiate another connector with the ServiceURL from above response.
            ConnectorClient connectorSend = new ConnectorClient(new Uri(response.ServiceUrl));
            IMessageActivity msg = Activity.CreateMessageActivity();
            msg.Recipient = new ChannelAccount("sip:XXXXX@XXXXX.onmicrosoft.com", "Agent");
            msg.Text = "text message";
            msg.Locale = "en-Us";
            msg.From = new ChannelAccount("sip:XXXXXbot@XXXXX.onmicrosoft.com", "Bot");
            msg.Type = ActivityTypes.Message;
            msg.Timestamp = DateTime.UtcNow;
            msg.ChannelId = "skypeforbusiness";
            msg.ServiceUrl = response.ServiceUrl;
            msg.Conversation = new ConversationAccount(isGroup: true, id: response.Id, name: null);
            //Send the message from Bot to User
            //var result = connectorSend.Conversations.SendToConversationAsync(msg.Conversation.Id, (Activity)msg).Result;
            await connector.Conversations.SendToConversationAsync((Activity)msg);

            var resp = new HttpResponseMessage(HttpStatusCode.OK);

            return resp;

        }
        catch (Exception ex)
        {
            return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您引用的第一个文档指出:

  

只要用户正在与机器人进行用户发起的对话   并且仍然打开Skype对话窗口

这是Skype for Business Bots(预览版)的局限性。

相关问题