
Hi,
We are setting some variables via javascript with our bot. It works, except that because of what seems to be an asynchronous code execution issue, the startConversation topic often doesn't have access to the variables before it launches. I could put in a delay in javascript as kind of a hack, but that isn't really desirable. I'm hoping there's a more elegant and simple solution.
Here is the current code:
const store = WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: "WEB_CHAT/SEND_EVENT",
payload: {
name: "pvaSetContext",
value: {
"orgType": "LCM",
"websiteName": "testWebsite"
}
},
});
// Add the startConversation event here
directLine
.postActivity({
localTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
locale,
name: 'startConversation',
type: 'event'
})
.subscribe();
}
return next(action);
});
It has the variable in startConversation about 50% of the time. Which we're using to change the first message the user sees depending on the website. Open to solutions other than this as well. We initially used the querystring variation, but then added some other javascript to trigger an event that resets the conversation. We may be able to achieve this another way with refreshing an iframe possibly and then we could use the querystring version. But if there's a way to do it with the javascript that I haven't figured out, that would be great.
Thanks for any tips!
Wesley