简体   繁体   English

发送对话历史 API 返回 HTTP 400 BotFramework

[英]Send Conversation History API returning HTTP 400 BotFramework

I'm trying to sendConversation History API provided by Microsoft in BotFramework Documentation .我正在尝试发送 Microsoft 在BotFramework 文档中提供的对话历史记录 API 。 It takes Transcript object (array of activities) as the input.它将成绩单 object(活动数组)作为输入。 But I've getting HTTP 400 Bad Request when using trying that.但是我在尝试使用时收到 HTTP 400 Bad Request 。

I'm making a POST request on this and authenticating it using JWT Token generated by client credentials for the bot.我正在对此发出 POST 请求,并使用机器人的客户端凭据生成的 JWT 令牌对其进行身份验证。

https://directline.botframework.com/v3/conversations/HBoZPkTiBYOAadigqEqFaJ-us/activities/history

This is the error I get.这是我得到的错误。

{
    "error": {
        "code": "BadSyntax",
        "message": "Invalid or missing activities"
    }
}

This is the activity array payload that I'm using这是我正在使用的活动数组有效负载

[    
    {
        "type": "message",
        "id": "HBoZPkTiBYOAadigqEqFaJ-us|0000003",
        "timestamp": "2022-09-05T08:10:00.3574378Z",
        "localTimestamp": "2022-09-05T13:39:57.633+05:30",
        "localTimezone": "Asia/Calcutta",
        "serviceUrl": "https://directline.botframework.com/",
        "channelId": "directline",
        "from": {
            "id": "dl_uID1",
            "name": "userName"
        },
        "conversation": {
            "id": "HBoZPkTiBYOAadigqEqFaJ-us"
        },
        "recipient": {
            "id": "bot-name-dev@abcd",
            "name": "bot-name-dev"
        },
        "textFormat": "plain",
        "locale": "en-GB",
        "text": "hi",
        "channelData": {
            "clientActivityID": "1662365337633rmq6e8mbm09",
            "clientTimestamp": "2022-09-05T08:09:57.633Z"
        }
    }
]

I'm not able to figure out what's the correct format of activity object that it is expecting.我无法弄清楚它所期望的活动 object 的正确格式是什么。

Create the bot and get it connected to the Direct Line.创建机器人并将其连接到 Direct Line。 Get the secret keys of the site that need to connect.获取需要连接的站点的密钥。 Before calling SendConversationHistory if the message is delivered to the recipient, it will create the bad request error message as it is unable to get the conversation history as the message was already received.如果消息已传递给收件人,则在调用SendConversationHistory之前,它将创建错误的请求错误消息,因为它无法获取会话历史记录,因为已收到消息。 SendConversationHistory must be called before sending the message then the Conversation History will be tracked. SendConversationHistory必须在发送消息之前调用,然后会话历史记录将被跟踪。 The below screens will be helpful to create the DirectLine connection to the bot created.以下屏幕将有助于创建与创建的机器人的DirectLine连接。 Then needed to add the trusted sites to DirectLine .然后需要将受信任的站点添加到DirectLine Then proceed with the code sample mentioned below which takes the conversation history.然后继续下面提到的代码示例,该示例获取对话历史记录。

在此处输入图像描述

Click on Create a resource点击创建资源

在此处输入图像描述

Search for bot and click on create搜索机器人并点击创建

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

Select Channels Select通道

在此处输入图像描述

在此处输入图像描述

Get the App Service Extension Keys and click on Default_site获取应用服务扩展密钥并单击Default_site

在此处输入图像描述

Click on the toggle and enable the enhanced authentication options and add the website which we need to communicate.单击切换开关并启用增强的身份验证选项并添加我们需要通信的网站。 In the code block of the current working application, to get the conversation history, use the following code block.在当前工作应用程序的代码块中,要获取对话历史记录,请使用以下代码块。

foreach (var a in activities)
{
    incrementId++;
    // Use your own ID format
    a.Id = string.Concat("history|", incrementId.ToString().PadLeft(7, '0'));
    a.ChannelData = null;
    a.Conversation = new ConversationAccount(id: convId);

    if (a.From.Name == message.Recipient.Name)
    {
        // Bot to recipient connection 
        a.Recipient = message.From;
        a.From = message.Recipient;
    }
    else
    {
        // User to bot connection (here bot will be the recipient)
        a.Recipient = message.Recipient;
        a.From = message.From;
    }
}

After connecting with Microsoft, I found this is the correct payload for this API.与 Microsoft 连接后,我发现这是此 API 的正确有效负载。

{
  "activities": [
   
       {
    "type": "message",
    "id": "whatever-conversation-id-in|0000000",
    "timestamp": "2022-11-20T20:14:26.242902Z",
    "serviceUrl": "https://directline.botframework.com/",
    "channelId": "directline",
    "from": {
        "id": "dl_test_id",
        "name": ""
    },
    "conversation": {
        "id": "whatever-conversation-id-in"
       
    },
    "recipient": {
        "id": "ABC_bot",
        "name": "ABC_bot"
    },
    "text": "Hello Bot"
}
]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM