I am trying to inject channelData with each message that is sent from a bot webchat control in a page. I looked around and found this sample (https://cmsdk.com/javascript/how-to-send-custom-channel-data-when-using-web-chat-client-with-bot-framework.html) and my code looks like the code below.
The issue is that this works in Chrome but the spread operator (…) doesn’t work on Edge or IE. Is there an alternative syntax that would work in all browsers?
var user = {
id: '@User.Identity.Name',
name: '@User.Identity.Name'
};
var bot = {
id: BotId,
name: 'BotName'
};
var botConnect = new BotChat.DirectLine({
secret: '@ViewData["BotSecret"]',
webSockets: 'true'
});
var v = { ...botConnect };
debugger;
BotChat.App({
botConnection: {
...botConnect,
postActivity: activity => {
activity.channelData = {
StudentId: '@User.Identity.Name'
};
return botConnect.postActivity(activity);
}
},
user: user,
bot: bot,
resize: 'detect'
}, document.getElementById("bot"));
It looks like Babel has a plugin which transforms the Spread operator into equivalent code using
Object.assign. This doesn't fully solve your problem, as IE still doesn't supportObject.assign- in the case of Babel, a polyfill is included forObject.Assign. Although including Babel in your project might be overkill, the MDN has sample code for a simple standaloneObject.assignpolyfill that might be more reasonable to include.If that's an agreeable dependency, then once
Object.assignis available to you cross-browser, the Babel documentation suggests that the two lines of code are equivalent: