I'm working with Oracle chatbots and Google Home, and I'm building an app in actions on google whose data is processed by the Oracle bot. But I found a problem with comunication between both. They comunicate through webhook, I have an app that receive user inputs and send it to the chatbot, but the chatbot send back the reply in an asynchronous way, and I can't take the data of the reply in the POST request and show it to the user, so I have to send a Media response to the user to wait the reply from bot, and after call to another action to check if reply is ready.
I'd like to get the reply synchronously, or at least not having to send a Media Response to wait the bot reply. Is it possible?
I have to use Oracle chatbots and Google Home.
This question contains my code: How to make asynchronous calls from external services to actions on google?
EDIT:
The /text
endpoint sends user inputs to my chatbot
app.intent('actions.intent.MAIN', conv => {
console.log('entra en main');
conv.ask('Hi, how is it going?');
});
app.intent('actions.intent.TEXT', (conv, input) => {
var userId = conv.body.user.userId;
console.log(userId);
if(userId && input){
return textFound(conv, input, userId);
}else{
textnotFound(conv);
}
});
express_app.post('/text', app);
The chatbot sends the reply to another endpoint:
express_app.post('/webhook', bodyParser.json(), (req, res)=>{
message = req.body;
const userId = req.body.userId;
if (!userId) {
return res.status(400).send('Missing User ID');
}
if (webhook.verifyMessageFromBot(req.get('X-Hub-Signature'), req.body, metadata.channelSecretKey)) {
console.log("todo bien");
res.sendStatus(200);
} else {
console.log("Todo mal");
res.sendStatus(403);
}
});
From here I can't send the data from reply to actions-on-google, I have to save the data in a queue and after call to TEXT action again to check the queue. I'd like to get the reply in the calback of the initial request if it's possible, or get another workaround to solve this problem.
I solved this problem with the pub-sub library of node. When app receive a message from GH user subscribe with their id to a function that will process the bot response
var token = PubSub.subscribe(user_id, commandResponse);
.When the app receive a response from bot in another different endpoint, the app publish the message in the user_id topic
PubSub.publish(userId, message);
, this message is proccesed by commandResponse function and sent to GH.This function is imlemented inside a Promise in the action endpoint of GH.