Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send message from Postman to Microsoft Bot

Tags:

botframework

I am trying to send a message to a bot I created and published to azure services so that the bot can then start messaging some of its users.

I am trying to make the requests on Postman first so that then I can build a controller for that interaction.

I am doing the following request:

POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded
Body:
grant_type:client_credentials
client_id: my_ms_app_id
client_secret: my_ms_app_secret
scope: https://api.botframework.com/.default

from this I get in the response the Bearer Authorization:

{
  "token_type": "Bearer",
  "expires_in": 3599,
  "ext_expires_in": 0,
  "access_token": "eyJ0eXA..."
}

Then I proceed with the following request:

POST https://skype.botframework.com/v3/conversations
Content-Type: application/json
Authorization: Bearer eyJ0eXAi....

{
    "bot": {
        "id": "i don't have this id so i pass some string",
        "name": "connector controller"
    },
    "isGroup": false,
    "members": [
        {
            "id": "28:...", //ID of the bot I want to send the message to
            "name": "Sp Bot"//Name of the bot I want to talk to
        },
       {
            "id": "i don't have this id so i pass some string",
            "name": "connector controller"
        }
    ],
    "topicName": "News Alert"
}

in response i get the conversation id which matches "id": "i don't have this id so i pass some string": { "id": "i don't have this id so i pass some string" }

Then I proceed with the following POST request:

POST. https://skype.botframework.com/v3/conversations/i don't have this id so i pass some string/activities
Authorization: Bearer eyJ0...
Content-Type:application/json

I get the following response:

400 Bad Request

{
  "error": {
    "code": "ServiceError",
    "message": "The conversationId 29... and bot .... doesn't match a known conversation"
  }
}

It looks like the problem occurs between the second and the 3 post method. It looks like that the https://skype.botframework.com/v3/conversations does not generate a conversation with the bot with Id I entered.

So when I make the final call to the bot: https://skype.botframework.com/v3/conversations/.../activities I always get the serviceError message.

like image 709
JoaoFilipeClementeMartins Avatar asked Apr 07 '17 10:04

JoaoFilipeClementeMartins


1 Answers

Based on your comments you are trying to create a custom "channel/client" to talk with the bot.

For doing that, I would recommend taking a look to Direct Line which seems the way to go for achieving your requirement.

I'm not sure which language are you using, so I will send you pointers to both C# and Node.

These are samples that will show you how to create custom client using Direct Line to interact with your bot:

C#

  • Basic Direct Line sample
  • Direct Line sample using Web Sockets

Node.js

  • Basic Direct Line sample
  • Direct Line sample using Web Sockets

All the samples are using a console app as the "custom channel".

like image 160
Ezequiel Jadib Avatar answered Oct 14 '22 08:10

Ezequiel Jadib