I am trying to connect to a bot Service using an Angular Client. I am able to connect to the Bot Service, but as soon as I post a message Activity, the WebChat client is sending a conversationUpdate event to the Bot, due to which I receive a Sign In Card from the Bot. (If I send userToken in channelData of firstMessage to Bot Service from client, i will not get the Sign In card).
I am trying to send a activity with userToken inside channelData, but the conversationUpdate event reaches Bot Service before my message activity and I receive a Sign In card.
I need to send custom channelData with the conversationUpdate event being sent from Client.
Using backchannel mechanism, i am able to send custom channelData for posting acctivities, but this conversationUpdate event is being triggered internally from websocket and I need to intercept this event trigger.
Following are the code details:
Index.html
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<script src="https://unpkg.com/simple-update-in/dist/simple-update-in.production.min.js"></script>
app.component.ts
// after response from https://directline.botframework.com/v3/directline/conversations
createDirectLine(response: any) {
this.directLine = window.WebChat.createDirectLine({
token: response.token,
webSocket: true,
streamUrl: response.streamUrl,
conversationId: response.conversationId
});
}
this.store = window.WebChat.createStore({},
({dispatch}) => next => action => {
if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
// add custom channelData to every postActivity
action = window.simpleUpdateIn(action, ['payload', 'activity', 'channelData', 'UserToken'], function () { return this.userToken; });
}
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
// Send event to bot with custom data
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
activity: {
type : 'conversationUpdate',
channelData : { 'UserToken : this.userToken}
}
}
})
}
return next(action);
});
renderWebChat() {
window.WebChat.renderWebChat(
{
directLine: this.directLine,
store: this.store
},
this.botWindowElement.nativeElement
);
}
P.S. This is'nt the full code, I have only added snippets.