node.js - Correct way to send response when using Actions-on-google with koa.js


Question: 

I'm trying to use actions-on-google with koa framework. I can't understand which request and response to use with AoG constructor in koa middleware.

This is my code:

const Koa = require( 'koa' )
const koaBody = require('koa-body')
const { DialogflowApp } = require('actions-on-google')

const koaApp = new Koa()
koaApp.use(koaBody())

koaApp.use(async (ctx) => {
    const googleAssistant = new DialogflowApp({request: ctx.request, response: ctx.response});
    const body = ctx.request.body;
    console.log(body)
    if (!body.result) ctx.throw(400, 'wrong request')

    ...

    const listItems = []
    results.forEach((result, i) => {
        listItems.push(
            googleAssistant.buildOptionItem('Item'+(i+1))
                .setTitle(result.title)
                .setDescription(result.text)
        )
    })
    const list = googleAssistant.buildList().addItems(listItems)
    console.log('Response to Dialogflow (AoG): ' + JSON.stringify(list))
    googleAssistant.askWithList('Here some results', list)
})

const PORT = process.env.PORT || 3000
koaApp.listen( PORT, () => {
   console.log( `Listening on ${ PORT }` )
} )

Trying it on AoG console Simulator I get the following error:

server error TypeError: this.response_.status is not a function 
    at DialogflowApp.doResponse_ (/home/zhuiks/myProject/node_modules/actions-on-google/assistant-app.js:2372:41)
    at DialogflowApp.askWithList (/home/zhuiks/myProject/node_modules/actions-on-google/dialogflow-app.js:620:17)
    at setGoogleResponse (/home/zhuiks/myProject/app.js:73:25)
    at koaApp.use (/home/zhuiks/myProject/app.js:88:9)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:169:7)

If I use json response instead of .ask() it works fine. I'm just not sure about full json response format for Dialogflow fulfillment in case of AoG request




1 Answer: 

The Node.js Client Library for Actions on Google expects a Express-style request/response pair.

 

More Articles


javascript - Sending HTTP Requests Through Azure

I am trying to interact with Urbanairship via their broadcast API to send notifications to android devices on an INSERT into a Azure table.My JavaScript INSERT code on Azure is as follows: function insert(item, user, request) { request.execute({ success: function() {

Azure DNS hostname or IP reference in web.config?

When connecting to Azure services in my applications, is it preferable to use the DNS hostname or the IP?For example, I have a SQL Server hosted in a virtual machine. Should I configure my web.config with 168.63.xxx.xxx or with mysqlserver001.cloudapp.net?Thanks

asp.net mvc - Payment Gateway returns Error HTTP Status - 400

I’m trying to redirect my MVC project to pay migs payment Gateway.Here’s the URL generated by my code. (For security reasons i have changed the value with the word “value” )https://migs.mastercard.com.au/vpcpay?vpc_AccessCode=value&vpc_Amount=100&vpc_Command=pay&vpc_Locale=en&vpc_Me


WebSocket closing immediately using Watson Speech-to-text JS SDK

Trying to use this code from a provided demo, using the latest watson-speech.js from https://github.com/watson-developer-cloud/speech-javascript-sdk:document.querySelector('#button').onclick = function () { fetch('myserverurl/api/token') .then(function(response) { return response.text(); }).

node.js - Microsoft Botframework Prompts.choice not getting validation response

I am using chatconnector to connect my Bot to an frontend chat app and writing the bot's response to my own database. The problem is when I am validating a prompt the bot responds but there's no API for me to grab the validation response. bot.dialog('/', [function (session) { builder.Prompts.cho

actions on google - Implementing Conversation Webhook as Azure Function App

I have an azure function app that I am using as a webhook for my google assistant action. I've tried to follow the documentation for the proper response but I continually get the following error in the simulator when testing my webhook. Is there anything in my response message that looks wrong?Fai


java - Paypal expressCheckout integration (DoExpressCheckout) error

I have a ExpressCheckout integration setup in java google app engine and it working up to GetExpresschekout .but in finall call(DoExpressCheckout) I am unable to Authorize payment .it returnsan errorRESULT=1000&PNREF=E24P1FBB8FA4&RESPMSG=Generic processor error: 13116-The transaction is in p

c# - Set time limit for items in container in CosmosDB using Microsoft.Bot.Builder.Azure (bot framework v4)

I want to set the time to live for the items in a container in cosmosDB, but I am not sure how to do so using the config of cosmosdb storage in bot framework v4. I would appreciate some help on this matter.I have read about setting time to live using DocumentClient() as documented here. However I se

c# - How to connect with bot from another app?

I have created a core bot with basic workflow to collect information from end-users, which is hosted on http://localhost:3978, and exposes an endpoint to send message http://localhost:3978/api/messages (POST) I can start and chat with bot via Bot Framework Emulator, but I dont know how to interact w

c# - Microsoft Bot Framework works locally, but fails remotely

I have this bot that is fairly complicated, but it works locally. But as soon as I publish it, it fails with the error: Sorry, my bot code is having an issue.I have tried using Application Insights, but it isn't showing the error details.The error always happens at the same point:/// <summary>