If you want to get either of those values (or any others, for that matter), then you should send the data via channelData
. You can do so a couple different ways via Web Chat's store
:
1) DIRECT_LINE/POST_ACTIVITY - In this example, if an activity is posted that also includes the text "send user details" (i.e. a card button is pressed that also displays text to the user), then userId
and userDetails
will be appended and sent as channelData
data points. In this case, only the message (or postBack, etc.) activity is received by the bot. (Sample reference here.)
<script src="https://unpkg.com/simple-update-in/dist/simple-update-in.production.min.js"></script>
const store = window.WebChat.createStore( {}, ( { dispatch } ) => next => async action => {
if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
if(action.payload.activity && action.payload.activity.text) {
let text = action.payload.activity.text.toLowerCase();
if(text === 'send user details') {
const userId = 'xyz789';
const userDetails = { 'name': 'Bob', 'age': 35, 'features': { 'eyes': 'brown', 'hair': 'blonde' }};
action = window.simpleUpdateIn(
action,
['payload', 'activity', 'channelData'],
() => ({
'userId': userId,
'userDetails': userDetails
})
)
}
}
}
return next( action );
} );
** 2) WEB_CHAT/SEND_EVENT** - In this example, again, if an activity is posted that also includes the text "send user details", then a separate event activity is produced and sent simultaneously that then includes both userId
and userDetails
as channelData
data points. In this case, two activities are received by the bot: a message (or postBack, etc.) activity and an event activity. (Sample reference here.)
const store = window.WebChat.createStore( {}, ( { dispatch } ) => next => async action => {
if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
if(action.payload.activity && action.payload.activity.text) {
let text = action.payload.activity.text.toLowerCase();
if(text === 'send user details') {
const userId = 'xyz789';
const userDetails = { 'name': 'Bob', 'age': 35, 'features': { 'eyes': 'brown', 'hair': 'blonde' }};
dispatch( {
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'LOGIN_SUCCESS',
value: {
userId,
userDetails
}
}
} )
}
}
}
return next( action );
} );
In both cases, for simplicity, the activity only posts when an incoming activity contains the text "send user datails". Also, note that I am demonstrating two ways of utilizing the store: indirectly and directly calling dispatch()
.
Hope of help!