当用户的帐户被锁定时向用户发送短信通知消息,我该如何在C#中做到这一点

时间:2019-05-17 15:11:21

标签: c# sms twilio botframework proactive

启动信息 SDK:C# 活动频道:SMS(Twilio) Bot版本:v4.4.3

问题描述: 我希望能够通过SMS消息发送主动消息。当用户的帐户被锁定时,我会拥有该人的电话号码,并且我想发送一条通知消息,例如“您的帐户已被锁定,请执行某些操作”。这可能吗? 我检查了有关主动消息的文档,该文档通过“活动”获得“ ConversationReference”,我不知道电话号码,我可以创建“ ConversationReference”对象,以及如何通过notify告诉机器人有关电话号码的信息控制器。

谢谢。

2 个答案:

答案 0 :(得分:2)

这里是Twilio开发人员的传播者。

如果您还没有以前的对话中的对话参考,则文档对于如何开始对话似乎并不明确。在这种情况下,直接send the user the SMS message using the Twilio API可能更容易。

答案 1 :(得分:1)

幸运的是,与大多数渠道不同,您可以构造会话参考,而无需让用户先向机器人发送消息,因为您知道用户的号码并且拥有机器人的号码。看看下面的代码片段。您可以通过向http://localhost:3978/api/notify/+1##########

发送获取请求,向电话号码发送主动消息
using Microsoft.Bot.Connector.Authentication;

[HttpGet("{number}")]
public async Task<IActionResult> Get(string number)
{
    MicrosoftAppCredentials.TrustServiceUrl("https://sms.botframework.com/"); 

    var conversationReference = new ConversationReference {
        User = new ChannelAccount { Id = number },
        Bot = new ChannelAccount { Id = "<BOT_NUMBER>" },
        Conversation = new ConversationAccount { Id = number },
        ServiceUrl = "https://sms.botframework.com/"
    };

    await ((BotAdapter)_adapter).ContinueConversationAsync(_appId, conversationReference, BotCallback, default(CancellationToken));

    // Let the caller know proactive messages have been sent
    return new ContentResult()
    {
        Content = "<html><body><h1>Proactive messages have been sent.</h1></body></html>",
        ContentType = "text/html",
        StatusCode = (int)HttpStatusCode.OK,
    };
}

private async Task BotCallback(ITurnContext turnContext, CancellationToken cancellationToken)
{
    await turnContext.SendActivityAsync("proactive hello");
}

有关发送主动消息的更多详细信息,请查看Proactive Message sample

希望这会有所帮助。

相关问题