如何使用 Azure 函数使用各种渠道向用户发送主动通知/广播消息



我需要通过Microsoft Bot V4 向用户发送在特定时间安排的主动通知。我不完全确定如何进行此操作。

目前,我正在尝试使用 Azure 函数向用户发送主动消息,但是,我不确定使用什么来连接机器人服务和 Azure 函数。我看了直线,但对我来说不清楚。

目前,我能想到的最佳方法是使用 Azure 函数和直线向用户发送主动通知。

我通过邮递员测试了直接 API,但它不起作用。它说找不到会话 ID。

https://directline.botframework.com/v3/directline/conversations/{conversationId}/activities

杰伦斯发布

{
    "type": "message",
    "from": {
        "id": "user1"
    },
    "text": "hello"
}

发送消息后,它应该给我 ID。

{
    "id": "0001"
}

编辑:

我设法理解了直线的问题。它不允许我向其他频道发送消息,例如网络聊天或Skype上的机器人。还有其他选项可以在Skype上向我的用户发送消息吗?

您需要创建输出机器人框架和 下面是 azure 函数的绑定信息,该函数将在每 x 分钟触发一次

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 */1 * * * *"
    },
    {
      "type": "bot",
      "name": "$return",
      "botId": "Azurefunction",
      "secret": "AppSettingNameOfYourBot",
      "direction": "out"
    }
  ],
  "disabled": false
}

而 Azure 函数是

使用系统;使用 System.Net;使用 System.Net.Http;使用 Microsoft.Azure.WebJobs.Host;

公共类机器人消息{ 公共字符串源 { get; set; } 公共字符串消息 { get; set; }}

public static BotMessage  Run(TimerInfo myTimer ,TraceWriter log)
{
    BotMessage message = new BotMessage()
    {
        Source = "AzureFunction",
        Message = "Testing"
    };
    return message;
}

此外,绑定配置设置为使用函数的返回值(在本例中,该值与绑定支持的任何类型都不匹配(,这就是在机器人和 Azure 函数之间建立连接的方式。

对于直接 api 相关问题,请检查此线程

无法在机器人框架中使用直线 api 发送消息

希望对您有所帮助。

好的,所以我解决了我的问题。通过使用 REST 连接器 https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-authentication?view=azure-bot-service-4.0 我想我只是做了一个很大的假设,即我必须使用直线

可能没有解释清楚我的问题到底是什么。感谢您的回复!

最新更新