-1

I'm trying to integrate the backchannel and getting the values. https://github.com/Microsoft/BotFramework-WebChat/tree/master/samples/15.d.backchannel-send-welcome-event

I also tried this. Get URL Referer and Origin header from Microsoft Bot Framework

I also tried deserializing the values still not able to get the data. how can i get the language values?

here's my sample code:

        var userinfo = {
            id: 'user-id',
            name: 'user name',
            locale: 'es'
        };
        var botConnection = new BotChat.DirectLine({
            token: 'mytoken',
            user: userinfo,
            locale: 'es'
        });
        BotChat.App({
            botConnection : botConnection,
            user: userinfo,
            bot: { id: 'bot-id', name: 'bot name' },

        }, document.getElementById('botDiv'));
        botConnection
            .postActivity({
                from: userinfo,
                name: 'ConversationUpdate',
                type: 'event',
                value: '',
            })
            .subscribe(function (id) {
                console.log('"trigger ConversationUpdate" sent');
            });

The purpose of this I want to pass the locale to my bot from my website. just like in the emulator. enter image description here Thanks!

edoms06
  • 89
  • 2
  • 11

1 Answers1

1

I would recommend adding the locale to the back channel event's channel data. That way on the bot side you can simply access the locale in the incoming activity without having to deserialize any JSON objects when you receive the event. Note, you can also use text or value in place of channelData. See the code snippets below.

BotChat Back Channel Event

// Send back channel event
botConnection.postActivity({
    from: userinfo,
    name: 'setLocale',
    type: 'event',
    channelData: "es"
}).subscribe(id => console.log(id));

Bot - C#

public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{

    if (turnContext.Activity.Type == ActivityTypes.Message)
    {
        ...
    } else if (turnContext.Activity.Type == "event") {
        // Check for `setLocale` events
        if (turnContext.Activity.Name == "setLocale") {
            await turnContext.SendActivityAsync($"Your locale is set to {turnContext.Activity.ChannelData}");
        }
    }
    else
    {
        await turnContext.SendActivityAsync($"{turnContext.Activity.Type} event detected");
    }
}

Hope this helps!

tdurnford
  • 3,632
  • 2
  • 6
  • 15
  • I don't know why this code suddenly works. I'm sure that I already tried this code. Sudden miracle happens. thanks man! – edoms06 Apr 03 '19 at 03:56