Search code examples
botframeworkdirect-line-botframework

How to add additional payload to botframework messages (DirectLine)


I'm developing bot using MS Bot Framework. We have native mobile app client for this bot also, so the only option for us is to use DirectLine API via sockets.

I wonder if it possible to add custom payload to messages which bot send to the client.

Say I want to return a message which will have 20 locations, every location is a ThumbnailCard attachment with image, title, subtitle and text, I also want to add more information like lat, lon, open time, close time etc. What is the best way to do this, is this possible?

I'm using NodeJS for my bot. And my IDE telling me that currently only these options are available for every ThumbnailCard attachment:

  • text
  • title
  • subtitle
  • images
  • tap

Previously I was using approach like this: message = new builder.Message(session) .attachments(thumbnails) .attachmentLayout('carousel') .entities([ { name: 'Location 1', lat: 10.11, lon: 10.11 }, { name: 'Mitul', lat: 10.11, lon: 10.11 } ]) .text('Select Location');

but then I found that if I supply 1 or 2 items in entities, than I receive it in my app, but if there are 5-10 objects with 10-30 properties, then I see not entities in the client at all. I think I'm using entities wrong here.

What is the best approach to add custom data to my bot messages, and are there any size limitation like how much objects I can pass along?


Solution

  • You can try using the sourceEvent property of the message. It's usually used to send payloads that are specific/native to a channel.

    Before Direct Line v3.0, attachments were not supported, and so the Direct Line sample was using the sourceEvent property to send them. You can see that in this code snapshot.

    enter image description here