c# - 适用于 Bot 框架 C# 的 Azure 函数

标签 c# azure botframework azure-functions

我已经使用 BotFramework 创建了一个机器人,并且我希望每 5 分钟触发一次 azure 函数(例如)。当它被触发时,我的机器人必须得到通知。

但我不知道该怎么做,我读了这个https://docs.botframework.com/en-us/azure-bot-service/templates/proactive/但问题是他没有使用定时器触发器 Azure Function,而是使用队列触发器。

我尝试做类似的事情:

using System;
using System.Net;
using System.Net.Http;
using Microsoft.Azure.WebJobs.Host;

public class BotMessage
{
    public string Source { get; set; } 
    public string Message { get; set; }
}


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

}

但我有这个错误:

2017-03-02T14:49:40.460 Microsoft.Azure.WebJobs.Host:索引方法“Functions.TimerTriggerCSharp1”出错。 Microsoft.Azure.WebJobs.Host:无法将参数“消息”绑定(bind)到类型 BotMessage&。确保绑定(bind)支持参数类型。如果您使用绑定(bind)扩展(例如 ServiceBus、Timers 等),请确保您已在启动代码中调用扩展的注册方法(例如 config.UseServiceBus()、config.UseTimers() 等) .).

此外,为了指示在触发事件时必须通知哪个机器人,添加了带有直线键的输出:

enter image description here

但正如你所看到的,存在与上面相同的错误......

有人有一些文档或示例吗?

感谢您阅读我的文章。

最佳答案

您的绑定(bind)配置设置为使用函数的返回值(此外,在本例中,该返回值与绑定(bind)支持的任何类型都不匹配)

您有几个选择:

  1. 取消选中该框以使用函数的返回值并将参数命名为 message

或者

  • 将函数的返回类型更改为 BotMessage从您的 Run 返回消息实例方法并删除 out BotMessage message参数。
  • 任一选项都可以解决此问题。

    关于c# - 适用于 Bot 框架 C# 的 Azure 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42559322/

    相关文章:

    c# - 使用 BufferedStream 包装 NetworkStream 以进行异步读取是否安全?

    c# - 将文件复制到 Azure WebRole 上的输出目录

    botframework - 发送图像而不是链接

    node.js - 如何从 MS Chatbot 内的 m.me 链接捕获推荐参数?

    botframework - 在 Bot Composer 中连接现有的 QnA 知识库

    c# - 系统.Net.WebException : The request was aborted: Could not create SSL/TLS secure channel

    c# - 如何修复 Entity Framework Core 错误 "Value cannot be null. Parameter name: frameworkName"?

    node.js - “newman”不被识别为内部或外部命令

    c# - 如何将 4 字节 unicode 字符插入 mysql 数据库?

    azure - 我们可以注册一个 Web 应用程序来接收来自 Azure 通知中心的通知吗?