Reputation: 69
I have to run a soundtrack (mp3 file) according to the reply given by Chatbot. So I need to identify the reply that comes from chatbot from my React component (or using pure JS). How can I do that?
Upvotes: 0
Views: 675
Reputation: 69
Thank you @Nicolas R. I changed that handleIncomingActivity() function as follows and send the activity.text value in to my chatbot react component as sending data from child(Chat.js) to parent(My react component) using callbacks. Here giveTextForBot() is a callback function which is given to react chatbot component as a prop.
Chat.prototype.handleIncomingActivity = function (activity) {
var state = this.store.getState();
switch (activity.type) {
case "message":
this.store.dispatch({ type: activity.from.id === state.connection.user.id ? 'Receive_Sent_Message' :'Receive_Message' , activity: activity });
if(activity.from.id === "<appName>"){
this.props.giveTextForBot(activity.text);
}
break;
case "typing":
if (activity.from.id !== state.connection.user.id)
this.store.dispatch({ type: 'Show_Typing', activity:activity });
break;
}
};
Upvotes: 0
Reputation: 14619
You can quickly found what you are looking for by searching the Webchat repository on Github.
If you search incoming
you will go to these lines which may be interesting for your needs:
private handleIncomingActivity(activity: Activity) {
let state = this.store.getState();
switch (activity.type) {
case "message":
this.store.dispatch<ChatActions>({ type: activity.from.id === state.connection.user.id ? 'Receive_Sent_Message' : 'Receive_Message', activity });
break;
case "typing":
if (activity.from.id !== state.connection.user.id)
this.store.dispatch<ChatActions>({ type: 'Show_Typing', activity });
break;
}
}
Upvotes: 1