Reputation: 33
I have deployed a Bot in Azure, the Bot displays a welcome message OnMemberAdd. Its adaptive card so the entered value are sent to stepcontext.value. I have integrated it with multiple channels, for directline, I would like to bypass the welcome card and pass the message directly to stepcontext.value so the second prompt is displayed instead of first. I have tried the below but it does not work, please help.
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Web Chat: Send welcome event</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<style>
html,
body {
height: 100%;
}
body {
margin: 0;
}
#webchat {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="webchat"></div>
<script>
(async function() {
// In this demo, we are using Direct Line token from MockBot.
// Your client code must provide either a secret or a token to talk to your bot.
// Tokens are more secure. To learn about the differences between secrets and tokens
// and to understand the risks associated with using secrets, visit https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication?view=azure-bot-service-4.0
const { token } = { token};
// We are using a customized store to add hooks to connect event
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'userInfo',
value: { fname:'user', lname:'test', pnumber:'0678775453'}
}
});
}
return next(action);
});
const styleOptions = {
botAvatarImage:
'',
botAvatarInitials: 'Chatbot',
userAvatarImage: '',
userAvatarInitials: 'User',
showNub: true,
bubbleFromUserNubOffset: 'bottom',
bubbleFromUserNubSize: 10,
bubbleFromUserBorderColor: '#0077CC',
bubbleNubOffset: 'top',
bubbleNubSize: 0,
bubbleBorderColor: '#009900',
sendBoxButtonColor: '#009900',
hideUploadButton: true,
hideSendBox : true
};
window.WebChat.renderWebChat(
{
directLine: window.WebChat.createDirectLine({ token }),
store,
styleOptions
},
document.getElementById('webchat')
);
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>
</body>
</html>
I have tried to send the data via postman and it works well but when I do it using above code it does not work.
Postman body
{
"type": "message",
"from": {
"id": "user1"
},
"value":
{
"fname":"user",
"lname":"test",
"pnumber":"0678787543"
}
}
Upvotes: 2
Views: 545
Reputation: 7241
You're so close! You have two options:
WEB_CHAT/SEND_EVENT
and include the name
property:const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'userInfo',
value: { fname:'user', lname:'test', pnumber:'0678775453'}
}
});
}
return next(action);
});
WEB_CHAT/SEND_MESSAGE
, include the text
property, and change to channelData
:const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_MESSAGE',
payload: {
text: 'userInfo',
channelData: { fname:'user', lname:'test', pnumber:'0678775453'}
}
});
}
return next(action);
});
===
I can see it coming through just fine using your code. Put a breakpoint in onTurn
/OnTurnAsync
and you'll see that when a user connects you get:
Upvotes: 1