通过BotFramework的restapi回复消息的最小示例?

2024-09-26 22:08:55 发布

您现在位置:Python中文网/ 问答频道 /正文

在用于Microsoft Botframework的Python webapp中,我希望reply to a message使用REST API call到{}。在

当我在本地机器上试用模拟器时,我发现REST调用的最小有效负载如下所示:

{
  "text": "Hello, Hello!",
  "from": {
    "address": "MyBot"
  },
  "channelConversationId": "ConvId"
}

其中"ConvId"是本地仿真器在原始消息中给出的id(注意,我必须发送channelConversationId而不是conversationId)。在

显然,这对于live bot连接器站点是不够的。但是,使用restapi调用/bot/v1.0/messages回复消息的(最小)示例是什么?在

我测试了不同的有效负载数据,例如文档中所示的属性fromtochannelConversationIdtext和{}。但通常我会遇到500错误:

^{pr2}$

当我试图发回原始消息时,刚好tofrom交换,我得到了一个不同的500错误:

{
  "error": {
     "code": "ServiceError",
     "message": "*Sorry, Web Chat is having a problem responding right now.*",
     "statusCode": 500
  }
}

Tags: totextfromrest消息messagehellobot
2条回答

同时,答案已经发布到a GitHub issue,引用了wiltodelta

Experimentally found necessary parameters for Slack, Skype, Telegram: ... ChannelConversationId only necessary Slack, otherwise the message will be added @userAddress.

Message message = new Message
{
  ChannelConversationId = channelConversationId,
  From = new ChannelAccount
  {
    ChannelId = channelId,
    Address = botAddress,
    IsBot = true
  },
  To = new ChannelAccount
  {
    ChannelId = channelId,
    Address = userAddress
  },
  Text = text
};

尤其是,属性replyToMessageIdchannelConversationId(前面提到的)是不必要的:它们指的是会话中最后看到的消息,因此在会话期间会发生变化。在

内联回复(作为响应返回)的最小有效负载为:

{ "text": "Hello, Hello!" }

如果您使用POST to /bot/v1.0/messages向带外发布回复,那么您是正确的,您需要更多。以下是我在Bot Builder SDK的节点版本中的操作:

^{pr2}$

向现有会话发送回复有点复杂,因为您必须包含将其返回到源会话所需的所有路由位。开始一个新的对话要容易得多:

^{3}$

两个示例都假定reply.text&;reply.language已经设置。在

相关问题 更多 >

    热门问题