botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

It is possible to send data through the Chat Control (iframe)?

Open Lipa9963 opened this issue 9 years ago • 16 comments

I'm investigating the possible use of a certain Snrio: Suppose my client click on link that leads to my Bot site Contains the Chat Control. the link also contains user Id (POST). so it is possible to send the bot this user id as soon as the customer enters the site? so the Bot can perform a specific process Against this User?

Thanks

Lipa9963 avatar Jan 08 '17 00:01 Lipa9963

Sounds like really valid scenario, @danmarshall is it possible for someone to pass data to chat control iframe? I am not sure though how would the interoperability will work with this.

maxpert avatar Jan 08 '17 16:01 maxpert

in addition, i know that i can use Direct Line API but It means I'll have to implement full client side (for example if the API (from bot side) send Cards with buttons to the client the user see only text and if i want it to show like in the Chat control or like in the emulator i should build this.. ) so if i can use the Built chat control and still Send through information It can be very effective.

Lipa9963 avatar Jan 08 '17 17:01 Lipa9963

Hi @Lipa9963 yes you can pass these additional URL parameters to your webchat iframe:

  • userid
  • username

This needs to be added to the documentation here and in the dev portal.

danmarshall avatar Jan 09 '17 20:01 danmarshall

@danmarshall Works. Thanks!

Lipa9963 avatar Jan 10 '17 15:01 Lipa9963

On Wed, Jan 11, 2017 at 1:27 PM, Praveen R [email protected] wrote:

@Lipa9963 https://github.com/Lipa9963 how do you achieved this? Like this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/BotBuilder/issues/1987#issuecomment-271845153, or mute the thread https://github.com/notifications/unsubscribe-auth/AWFzXVKR9d1YciB4lerNvMwV4IZ6ZxXwks5rRLydgaJpZM4LdkCZ .

Lipa9963 avatar Jan 11 '17 13:01 Lipa9963

Sounds like this issue has been resolved. Closing now. If I'm in error, please reopen!

eanders-ms avatar Jan 18 '17 21:01 eanders-ms

Hi guys, how can I read such parameters from the bot side? Thank you very much

0xMelkor avatar Jul 23 '17 17:07 0xMelkor

@insanediv is your bot in Node or C# ?

danmarshall avatar Jul 23 '17 17:07 danmarshall

Hi @danmarshall it is a node bot

0xMelkor avatar Jul 23 '17 18:07 0xMelkor

@insanediv see https://github.com/Microsoft/BotBuilder-Samples/tree/master/Node/core-GetConversationMembers

danmarshall avatar Jul 23 '17 18:07 danmarshall

@danmarshall is it possible to use this mechanism to pass arbitrary parameters to the bot via the web chat embed code?

0xMelkor avatar Jul 23 '17 19:07 0xMelkor

@insanediv no. For arbitrary values, you will need to host your own custom webchat page. See the "backchannel" in the WebChat repo readme and example.

danmarshall avatar Jul 23 '17 22:07 danmarshall

@danmarshall Thank you very much. I managed to pass custom parameters to my bot, but have another question: How is it possible to store such parameters to the session.userData object?

I show you my code:

Client side

 botConnection.postActivity({type: "event",
                             value: "customarg", 
                             from: {id: "me" }, 
                             name: "customEvent"})
                            .subscribe(id => console.log("success"));

Server side

bot.on("event", function (event) {
    var msg = new builder.Message().address(event.address);
    if (event.name === "customEvent") {
        // HOW CAN I STORE event.value IN session.userData ? 
        console.log(event.value);
    }
});

Thank you again

0xMelkor avatar Jul 24 '17 10:07 0xMelkor

I finally managed to solve this. For anyone that needs please visit my github page

0xMelkor avatar Jul 24 '17 15:07 0xMelkor

For those who would like to read the user ID and user name from a C# bot, they are available in the turn context, which in my bot is available in methods OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken) in class DialogBot.cs, and in OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken) in class QnABot.cs.

In these methods, turnContext.Activity.From.Id contains the passed-in user ID, and turnContext.Activity.From.Name contains the passed-in user name.

kds-snyder avatar Jun 14 '19 22:06 kds-snyder

@insanediv see https://github.com/Microsoft/BotBuilder-Samples/tree/master/Node/core-GetConversationMembers

I couldn't open this link, any idea how I could access the data passed in the iframe src in the bot? I am using nodejs thanks

noamanag avatar Sep 23 '20 07:09 noamanag