Как сохранить историю чата для существующего идентификатора разговора с API-интерфейсом прямой линии BotFramework 3.0? - PullRequest
1 голос
/ 04 февраля 2020

Я пытаюсь отобразить историю чата пользователя с моим ботом, чтобы, когда они вернутся, они могли видеть свои предыдущие разговоры. Когда я пытаюсь отправить объект транскрипта вversationsSendConversationHistory (String разговорId, история транскрипта).

Я получаю Запрещено (403), и история пользователя не отображается в чат-боте, но бот отвечает, что детали могут см в чате.

Кто-нибудь знает, как это исправить?

Я использую BotFramework SDK v.3 в Java и DirectLine API 3.0

API: https://directline.botframework.com/v3/conversations/1kDMfNnGZhF8N8IbW5gwGy--c/activities/history

JSON:

[
  {
    "action": null,
    "attachments": [],
    "attachmentLayout": null,
    "channelData": null,
    "channelId": "webchat",
    "conversation": {
      "id": "Ch3aQxbVKCULecS9Vp7kWm-c",
      "name": null,
      "isGroup": null
    },
    "entities": [],
    "from": {
      "id": "27c3a0d9120607d3969a06a0305a5a7f06645f46c0d5f006337ceca057838350",
      "name": "User"
    },
    "historyDisclosed": null,
    "id": "Ch3aQxbVKCULecS9Vp7kWm-c|20200207-141252-1",
    "locale": null,
    "localTimestamp": "2020-02-07T13:38:15.674Z",
    "membersAdded": [],
    "membersRemoved": [],
    "name": null,
    "recipient": {
      "id": "demobot-dev-de-dev@VeY8HxuBVIw",
      "name": "Demobot DEV DE"
    },
    "relatesTo": null,
    "replyToId": "Ch3aQxbVKCULecS9Vp7kWm-c|0000005",
    "serviceUrl": "https://directline.botframework.com/",
    "suggestedActions": null,
    "summary": null,
    "text": "USER- Hi",
    "textFormat": null,
    "timestamp": "2020-02-07T13:38:15.674Z",
    "topicName": null,
    "type": "message",
    "speak": "USER- Hi",
    "value": null,
    "event": false,
    "message": true,
    "tenantEvent": false
  },
  {
    "action": null,
    "attachments": [],
    "attachmentLayout": null,
    "channelData": null,
    "channelId": "webchat",
    "conversation": {
      "id": "Ch3aQxbVKCULecS9Vp7kWm-c",
      "name": null,
      "isGroup": null
    },
    "entities": [],
    "from": {
      "id": "demobot-dev-de-dev@VeY8HxuBVIw",
      "name": "Demobot DEV DE"
    },
    "historyDisclosed": null,
    "id": "Ch3aQxbVKCULecS9Vp7kWm-c|20200207-141252-2",
    "locale": null,
    "localTimestamp": "2020-02-07T13:38:15.687Z",
    "membersAdded": [],
    "membersRemoved": [],
    "name": null,
    "recipient": {
      "id": "27c3a0d9120607d3969a06a0305a5a7f06645f46c0d5f006337ceca057838350",
      "name": "User"
    },
    "relatesTo": null,
    "replyToId": "Ch3aQxbVKCULecS9Vp7kWm-c|0000001",
    "serviceUrl": "https://directline.botframework.com",
    "suggestedActions": null,
    "summary": null,
    "text": "BOT- Hallo ich bin der <b>DemoBot</b> und <a href=\"www.gmail.com\">zeige</a> dir die Plattform Features. Einfach auf eins der Quickreplies klicken und los geht's! Ach so... Und falls ich dich mal nicht verstehe wäre es schön, mich nachzutrainieren.",
    "textFormat": null,
    "timestamp": "2020-02-07T13:38:15.687Z",
    "topicName": null,
    "type": "message",
    "speak": "BOT- Hallo ich bin der <b>DemoBot</b> und <a href=\"www.gmail.com\">zeige</a> dir die Plattform Features. Einfach auf eins der Quickreplies klicken und los geht's! Ach so... Und falls ich dich mal nicht verstehe wäre es schön, mich nachzutrainieren.",
    "value": null,
    "event": false,
    "message": true,
    "tenantEvent": false
  },
  {
    "action": null,
    "attachments": [],
    "attachmentLayout": null,
    "channelData": null,
    "channelId": "webchat",
    "conversation": {
      "id": "Ch3aQxbVKCULecS9Vp7kWm-c",
      "name": null,
      "isGroup": null
    },
    "entities": [],
    "from": {
      "id": "27c3a0d9120607d3969a06a0305a5a7f06645f46c0d5f006337ceca057838350",
      "name": "User"
    },
    "historyDisclosed": null,
    "id": "Ch3aQxbVKCULecS9Vp7kWm-c|20200207-141252-3",
    "locale": null,
    "localTimestamp": "2020-02-07T14:12:42.638Z",
    "membersAdded": [],
    "membersRemoved": [],
    "name": null,
    "recipient": {
      "id": "demobot-dev-de-dev@VeY8HxuBVIw",
      "name": "Demobot DEV DE"
    },
    "relatesTo": null,
    "replyToId": "Ch3aQxbVKCULecS9Vp7kWm-c|0000005",
    "serviceUrl": "https://directline.botframework.com/",
    "suggestedActions": null,
    "summary": null,
    "text": "USER- I want to book the tickets",
    "textFormat": null,
    "timestamp": "2020-02-07T14:12:42.638Z",
    "topicName": null,
    "type": "message",
    "speak": "USER- I want to book the tickets",
    "value": null,
    "event": false,
    "message": true,
    "tenantEvent": false
  },
  {
    "action": null,
    "attachments": [],
    "attachmentLayout": null,
    "channelData": null,
    "channelId": "webchat",
    "conversation": {
      "id": "Ch3aQxbVKCULecS9Vp7kWm-c",
      "name": null,
      "isGroup": null
    },
    "entities": [],
    "from": {
      "id": "demobot-dev-de-dev@VeY8HxuBVIw",
      "name": "Demobot DEV DE"
    },
    "historyDisclosed": null,
    "id": "Ch3aQxbVKCULecS9Vp7kWm-c|20200207-141252-4",
    "locale": null,
    "localTimestamp": "2020-02-07T14:12:42.676Z",
    "membersAdded": [],
    "membersRemoved": [],
    "name": null,
    "recipient": {
      "id": "27c3a0d9120607d3969a06a0305a5a7f06645f46c0d5f006337ceca057838350",
      "name": "User"
    },
    "relatesTo": null,
    "replyToId": "Ch3aQxbVKCULecS9Vp7kWm-c|0000003",
    "serviceUrl": "https://directline.botframework.com",
    "suggestedActions": null,
    "summary": null,
    "text": "BOT- Darauf habe ich leider keine Antwort. Versuche es doch bitte mit einer anderen Formulierung",
    "textFormat": null,
    "timestamp": "2020-02-07T14:12:42.676Z",
    "topicName": null,
    "type": "message",
    "speak": "BOT- Darauf habe ich leider keine Antwort. Versuche es doch bitte mit einer anderen Formulierung",
    "value": null,
    "event": false,
    "message": true,
    "tenantEvent": false
  }
]

Код:

public void uploadChatHistroy(final String accessToken, final Activity activity, final List<Activity> history) {
    Transcript transcript = new Transcript();
    final String basePath = removeLastSlash(activity.getServiceUrl());
    final String conversationId = activity.getConversation().getId();
    Integer incrementId = 0;
    try {
        for (Activity activityHistory : history) {  
            incrementId++;
            activityHistory.setId(getRandomIdFromDate(conversationId) + incrementId);
            activityHistory.setChannelData(null);
            activityHistory.setServiceUrl(basePath);
            ConversationAccount conversation = new ConversationAccount();
            conversation.setId(activity.getConversation().getId());
            activityHistory.setConversation(conversation);

            if (activity.getFrom().getId().equals(activityHistory.getFrom().getId())) {
                // If the activity was from the user, assign the bot as the recipient
                activityHistory.setReplyToId(activity.getId());
                activityHistory.setFrom(activity.getFrom());
                activityHistory.setRecipient(activity.getRecipient());
            } else if (activity.getFrom().getId().equals(activityHistory.getRecipient().getId())) {
                // If the activity was from the bot, assign the user as the recipient

                activityHistory.setFrom(activity.getRecipient());
                activityHistory.setRecipient(activity.getFrom());
                activityHistory.setText("BOT- " + activityHistory.getText());
            }
            else {
                activityHistory.setFrom(activity.getRecipient());
                activityHistory.setRecipient(activity.getFrom());
                activityHistory.setText("BOT- " + activityHistory.getText());
            }

        }
        transcript.setActivities(history);

        getConversationsApi(accessToken, basePath).conversationsSendConversationHistory(conversationId, transcript);
    } catch (Exception e) {
        log.error("getConversationsApi: {} ", e.getMessage());
    }

}

Исключение:

channel.msbotframework.api.client.ApiException: Forbidden  
    at channel.msbotframework.api.client.ApiClient.handleResponse(ApiClient.java:951)  
    at channel.msbotframework.api.client.ApiClient.execute(ApiClient.java:867)  
    at channel.msbotframework.api.ConversationsApi.conversationsSendConversationHistoryWithHttpInfo(ConversationsApi.java:1192)  
    at channel.msbotframework.api.ConversationsApi.conversationsSendConversationHistory(ConversationsApi.java:1176)  

Поток моего приложения:

  1. Проверьте, существует ли сохраненный сеанс разговора или нет.
  2. Если разговор присутствует в сеансе, повторно подключитесь с использованием этого идентификатора разговора
  3. Отправьте событие бэкэнду приложение для восстановления истории
  4. Извлечение предыдущих действий из базы данных и создание объекта Transcript
  5. Внутренний вызов вызывает диалоговый интерфейс DiscussionsSendConversationHistory (разговорный идентификатор, транскрипт) и отправляет его по прямой линии API.

Здесь я получаю запрет всегда, когда нажимаю на данные пользователя.

Я могу общаться с ботом, даже если это не удается, используя старый идентификатор разговора. Я также пытался заставить бота выполнить ReplyToActivity, и это работает.

Кто-нибудь знает, как решить эту проблему?

...