Search code examples
azurebotframeworkdirect-line-botframework

Directline API message to Microsoft Bot


I have created the bot in azure services using LUIS, which used as chatbot and can create conversations using dialogs.

At some point, I am trying to push messages to chatbot using Direct Line API 3.0, I'm using Postman to send the messages to bot.

I followed the instructions from this page, https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-send-activity?view=azure-bot-service-4.0

I'm able to send message to the conversation as bot, below is the image I sent message from Postman and got successful response.

enter image description here

But my issue is, after the message is sent, the bot tries to analyse even though it's not user message. Bot starts to send message from default message handler like below,

enter image description here

Even after sending the message successfully, my bot triggers the default message handler, which is expected only to happen for user messages but not for bot messages.

Also, I have checked with webchat channel, which it doesn't trigger this default message handler. This is happening only in DirectLine API, can anyone help me on this.


Solution

  • Instead of sending the message as type "message", you should send it as "event". This way your MessagesController will see it as an ActivityType of Event instead of Message and you can process however you want without spaghettifying your actual message handling If you want to send different kinds of event to make it even easier, then you can 'name' you event by supplying the 'name' field with a value in your json. Third, if you need to include data with the message, you would supply a value in the 'value' field of your json.

    The github page for the standard webchat client has some great information on sending events. It might shed a bit more light on the json.

    You can read more about the 'event' activity type here

    You message json would look something more like this:

    {
        "type": "event",
        "from": {
            "id": "user1"
        },
        "name": "theEvent",
        "value": "someDataMyBotNeeds"
    }