takewheretrust
takewheretrust

Reputation: 61

How to send user information through directline botconnector

I'm building a mobile client to talk to a bot built with microsoft botbuilder through botconnector directline. I want to send things like the unique id of the user speaking with the bot, so my bot can operate on this user. Currently I'm just POSTing to directline, but when I add additional things in the body, my bot can't retrieve it. I'm probably doing something really simple wrong. Would love to get your help on this!

POST code from client:

sendToBot: function(setUpObj, message, returnCallback){
    var postURL=baseURL+"/"+setUpObj.conversationId+"/messages"
    var postOptions ={
       method: 'POST',
       headers: {
           "Authorization": setUpObj.conversationToken,
           "content-type": "application/json"
       },
       body: JSON.stringify({
         "text": message,
         "from": {
           'address': setUpObj.currentUserUid
         }
       })
     }


    fetch(postURL, postOptions)
      .then(
        (response)=>response.text()
      )
      .then(
        (responseText)=>{
                this.getResponse(setUpObj, returnCallback)
        }
      )


  }

and I'm accessing the the currentUserUid on the server by

session.message.from.address

Thanks for you patience.

Upvotes: 3

Views: 186

Answers (1)

rposbo
rposbo

Reputation: 327

Have you tried setting the channelData in the json? It's described as "data sent unmodified between client and bot" and can look like:

{
  "id": "CuvLPID4kDb|000000000000000004",
  "conversationId": "CuvLPID4kDb",
  "created": "2017-02-22T21:19:51.0357965Z",
  "from": "examplebot",
  "text": "Hello!",
  "channelData": {
    "examplefield": "abc123"
  }
}

https://docs.botframework.com/en-us/core-concepts/channeldata/

So in your code it could look like:

var postOptions ={
   method: 'POST',
   headers: {
       "Authorization": setUpObj.conversationToken,
       "content-type": "application/json"
   },
   body: JSON.stringify({
     "text": message,
     "channelData": {
       "from": {
        "address": setUpObj.currentUserUid
       }
     }
   })
 }

Upvotes: 1

Related Questions