0

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.

  • Can you update your question to include code that illustrates how you're handing the webhooks? – Prisoner Sep 30 '18 at 18:39
  • You answered me in another question, but I need a solution from oracle if in actions on google we haven't another solution. This was my question: https://stackoverflow.com/questions/52440050/how-to-make-asynchronous-calls-from-external-services-to-actions-on-google – Ignacio Dones Téllez Oct 01 '18 at 07:38
  • I'm not sure I understand what your question is, then. Are you asking how to handle the other question with Oracle's webhook or on Google's side? Again, can you update the question to show your code currently and what you think needs to be updated? – Prisoner Oct 01 '18 at 10:13
  • I'm asking if there is a workaround on Oracle's side to send the reply in the response of the initial request instead of sending the response asynchronously calling another endpoint. Because according to what you told me, on Google's side there isn't other solution if the bot works in this way. Sorry if I'm not making myself clear, english is not my language. – Ignacio Dones Téllez Oct 01 '18 at 10:32
  • I suggest you edit the question to be clear about exactly what you're looking for. It sounds like you want to know how to write an Oracle bot that can handle getting the information when the webhook is called, making an HTTP request, ignoring the response, waiting for a reply made to a separate webhook, and then replying as part of the original call. Is that correct? If so, ask that in the question and make it clear what you're trying to do and what your limitations are. – Prisoner Oct 01 '18 at 10:37

2 Answers2

2

If your webhook responds within 5 seconds, then you can do the whole setup inline. If your Action is written using Node.js, you can use Promises to insert asynchronous code. Below is an example snippet.

function getBotResponse() {
    return new Promise((resolve, reject) => {
        // Call bot
        resolve(botResponse);
    })
}

app.intent('get oracle bot', conv => {
    return getBotResponse()
        .then((botResponse) => {
            conv.ask(botResponse)
        });
})
Nick Felker
  • 11,536
  • 1
  • 21
  • 35
  • There are 2 problems with that workaround: The first is Bot may take more than 5 seconds to respond, the second problem is that the bot sends the reply to another endpoint, for that I have to send a Media response to the user and after call an action to check the replay. I can't access the reply from my action, I have to save the reply in a queue and check it in another action call. I'd like to solve this. – Ignacio Dones Téllez Oct 01 '18 at 07:36
  • If it takes more than 5 seconds, I'm not sure how adding Oracle's bot processing is going to help you. – Prisoner Oct 01 '18 at 10:38
  • Bot response MAY take more than 5 seconds, but it's not usual. I have to use this technologies, I don't decide which one to use. – Ignacio Dones Téllez Oct 01 '18 at 17:12
0

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.