1

Currently attempting to integrate Azure Bot Framework with external platforms like Integromat. I am using the code snippet below to send the first name and mobile number submitted by the user. The user input is sent to an integromat webhook, which sends a webhook response.

bot.dialog('WebTest', function (session) {
    session.send('conversation.id: ' + session.message.address.conversation.id);
    session.userData.convoID = session.message.address.conversation.id;
   // var request = require('request');         
   // var url = "https://hook.integromat.com/y6d18ahnsfanbkwqfdmygkwd2ft93vr2"
        request.post({   
            headers: { 'content-type': 'application/x-www-form-urlencoded' },
          url: 'https://hook.integromat.com/ynwbud77o7up7rrhl3m8tvdriquhtess',
                body: 'first=' + session.userData.first + '&mobile=' + session.userData.mobile + '&convoID=' +session.userData.convoID
        }).on('response', function (response) {
            //session.send(response);
            response.on('data', function (data) {
                console.log('data: ' + data);
            })
           // session.send(data)
        });    
   // session.send(data);
   //session.send(response);
    session.send("This service is still under construction");
}).triggerAction({ matches: /^webby/i })

The response is correctly logged in the console https://i.stack.imgur.com/XQC8u.png

However, I am not sure as how I would be able to send it back to the bot and display it to the user.

I have explored the Directline API as an option, acquiring the conversation ID and following the documentation. I used this link: https://directline.botframework.com/v3/directline/conversations/{{1.convoID}}/activities And sent the following request content as a json payload along with the authorization key as a header:

{
    "type": "message",
    "from": {
        "id": "user1"
    },
    "text": "hello"
}

Although for this, I am getting a 404 error, with a "BadArgument" and "Unknown conversation" error.

Any help that would put me in the right direction would be appreciated, thanks!

alvaro
  • 2,676
  • 2
  • 20
  • 19
Add
  • 13
  • 5
  • Just to be clear, you have an application that is getting the webhook response and processing it to be sent out to the bot (possibly via a directline connection). In this case, you aren't connecting to the webhook from within the bot itself. – Mark B Oct 11 '18 at 18:14

1 Answers1

1

I am not 100 percent sure what specifically you would like to do with your data within this function:

response.on('data', function (data) {
    console.log('data: ' + data);
})

But the reason that session.send(data) doesn't work after this should be due to data being an object rather than a string. In this case you can do anything to make the argument a string instead, from something as simple as JSON.stringify(data) to formatting an output with the fields.

If a directline call was made from inside the bot, it likely fired off without failure because you can communicate from bot to bot via that API; but if the conversationID resolves to one within the bot currently being used (or simply does not exist yet) then an error is expected.

Mark B
  • 581
  • 2
  • 14
  • 1
    Thank you! Actually ended up using something a bit different which was parsing the response with `var parseData = JSON.parse(data);` and displaying it back with `session.send(parseData.text);` – Add Oct 16 '18 at 08:01