his/her 帐户锁定时向用户发送短信通知消息,我如何在 C# 中执行此操作

Send sms notify message to user when his/her account locked, how can i do that in C#

机器人信息 开发工具包:C# 活动渠道:SMS (Twilio) 机器人版本:v4.4.3

问题描述: 我希望能够通过 SMS 消息发送主动消息。当用户的帐户被锁定时,我有那个人的 phone 号码,我想发送一条通知消息,例如 "your account is locked, please do something." 这可能吗? 我查看了有关主动消息的文档,它是通过 "activity" 获取 "ConversationReference",我不知道 phone 号码,我可以创建一个 "ConversationReference" 对象,并且如何通过通知控制器告诉机器人 phone 号码。

谢谢。

此处为 Twilio 开发人员布道师。

如果您还没有之前对话的对话参考,那么文档似乎并不清楚您将如何开始对话。在这种情况下,直接send the user the SMS message using the Twilio API可能更容易。

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

发送获取请求来向 phone 号码发送主动消息
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

希望对您有所帮助。