I am currently using react.js on the client side and node.js on the server side.The Webchat client communicates with the bot using directline. Is there a way to send out data from the bot to the client?
The data here are just an array of messages. I wish to initialise the bot with previous conversation messages. I tried sendConversationHistory() method but that doesn't seem to work well on deployment. Hence, I am thinking of fetching messages from the database, and then sending these obtained messages to the client.
I came across the backchannel approach where we can post activity from the client.I plan to post an activity called getHistory() from the Webchat client and when the server listens for this activity, it fetches the messages from the database and sends them as a response to the client.The client reads this response and renders accordingly.I plan to send data from the bot to the client,but I am unsure about the correct methods and syntax to use for sending this data from the bot.
Client end:
let messages;
function getMessages() {
botConnection
.postActivity({type: "event", value: "", from: {id: "me" }, name: "getHistory"})
.subscribe(res => messages = res);
}
I am not sure how will I proceed with the server end.
bot.on("event", function (event) {
let fetchedMessages = [];
fetchedMessages = fetchConversations(); /*a method which fetches the messages from the database*/
bot.send(fetchedMessages) ; /*unsure about this part*/
}
I am not sure about how the fetchedMessages would be sent to the client.I want the messages variable in client to be equal to fetchedMessages of the server.I am a beginner in javascript and still familiarizing with the bot framework. Thanks for reading!