FLG
FLG

Reputation: 41

How to respond to message from the Bot Framework (Direct Line Client)?

I want to create a dialog with the bot framework. My steps:

  1. Create a new Conversation using the Direct Line API (Works without problems) (Clientside)

  2. The following Dialog gets triggered in the Bot framework (Serverside):

    bot.dialog('*:notification', [
    function (session, args) {
      builder.Prompts.text(session, args)
    },
    function (session, results) {
      logger.info('Results', results)
    }])
    
  3. I want to send a reply to the incoming Message (Clientside)

    method:'post',
    url:'conversations/' + conversationId + '/activities',
    headers:{
        'Authorization': 'Bearer' + token
    }
    body:{
        replyToId: replyToId,
        type:'message',
        from: { 
            id:'myId'
        },
        text: 'Some simple text',
        textFormat: 'plain'
    }
    

conversationId: I use the one i recieved when i created the conversation

token: I use the one i recieved when i created the conversation

replyToId: The one from the activity Object

Actual Result:

  1. The Botframework does not recognize that this is the reply to the message send and triggers the default handler.

Expected Result:

  1. The Bot Framework triggers the second step of the Dialog.

Upvotes: 4

Views: 721

Answers (1)

Grace Feng
Grace Feng

Reputation: 16652

For the first thing, your dialog '*:notification' don't have a triggerAction, you can for example modify your dialog like this:

bot.dialog('*:notification', [
    function (session, args) {
      builder.Prompts.text(session, args)
    },
    function (session, results) {
      logger.info('Results', results)
}]).triggerAction({matches: /^notification/i});

Then you may use DL to send message from your client side to your bot and trigger this dialog like this:

method:'post',
url:'conversations/' + conversationId + '/activities',
headers:{
    'Authorization': 'Bearer' + token
}
body:{
    type:'message',
    from: { 
        "id": "1234",
        "firstname": "fname",
        "lastname": "lname"
    },
    text: 'notification',
    textFormat: 'plain'
}

Upvotes: 2

Related Questions