MS Bot Framework Direct Line API 3.0: Get starting message

720 Views Asked by At

I published a bot using the Azure bot framework to the Azure cloud servers, and made an application that uses the Direct Line API 3.0 to send user responses and receive bot messages through HTTP requests. Everything works except that I'm not sure how to get the starting message of the bot at the start of the conversation. I open the conversation with the /v3/directline/conversations endpoint, but I'm not sure how to receive the first message of the bot (that is normally sent without any user interaction). A message request after opening the conversation doesn't include any bot responses, but the next message request after sending the first user input includes the first two messages of the bot (starting message and response to the user).

EDIT: From reading this I came to the conclusion that it will be easier to just use a custom event as a trigger for the welcome message. I updated my bot as follows to reflect this within bot composer, adding a new CUSTOM event trigger with a test response message:

enter image description here

However, I still can't seem to trigger this event via the Direct Line API. Currently, I send a request as follows, following the event activity structure:

{ 
  "type": "event", 
  "channelId": "directline", 
  "from": { "id": "UnityUserId", "name": "Unity User 1" }, 
  "value": "test", 
  "name": "welcome" 
}

I then get a response with ID, normally indicating that the request was successfull. However, upon requesting the bot response messages, I get the following:

{
  "activities": [
    {
      "type": "event",
      "id": "5FZsHpWBxm1hjhWQYY7gr-eu|0000000",
      "timestamp": "2022-04-09T14:39:15.90169Z",
      "serviceUrl": "https://directline.botframework.com/",
      "channelId": "directline",
      "from": {
        "id": "UnityUserId",
        "name": "Unity User 1"
      },
      "conversation": {
        "id": "5FZsHpWBxm1hjhWQYY7gr-eu"
      },
      "value": "test",
      "name": "welcome"
    }
  ],
  "watermark": "0"
}

Indicating that the bot has no responses, which doesn't seem quite right when looking at the bot composer screenshot above. Is there something wrong with my current method?

Regards

2

There are 2 best solutions below

4
On
0
On

I thought I remembered seeing the bot's welcome message when using Direct Line, so I tried to quickly repro it again. I connected a simple echo bot via Direct Line. Then I created a conversation, sent a simple message, and then retrieved all activities (all via REST calls), and the bot's welcome message was indeed present in the response, as you can see in this screenshot:

enter image description here

Perhaps you should use these Direct Line 3.0 API reference docs as opposed to the one you linked above. I followed these steps using the basic Echo bot sample, Postman, and a bot resource in Azure for simple and easy testing, but you could use a full application if you wish.