actions-on-google-nodejs icon indicating copy to clipboard operation
actions-on-google-nodejs copied to clipboard

No support for koa web framework.

Open jonaskuiler opened this issue 5 years ago • 4 comments

Currently, only lambda functions and express are supported by actions-on-google.

I've created a koa framework for a project I'm working on and I thought it would be useful for others to make a pull request.

jonaskuiler avatar Mar 04 '19 15:03 jonaskuiler

I think that would be useful. In building the revised library, we wanted to ensure the framework was flexible enough to work with different frameworks, even if we didn't add them all ourselves. It may also be possible to build this as your own plugin that developers can include as an optional dependency.

Fleker avatar Mar 04 '19 15:03 Fleker

Hey Nick.

Like you said it's probably not the best idea to include all possible options for Node frameworks. I've created a pull request here #294. The implementation is probably not the hardest thing but I thought I'd submit it anyway. I did test it thoroughly in an existing project.

Please let me know if you would rather like this being a separate package.

jonaskuiler avatar Mar 04 '19 15:03 jonaskuiler

Thanks for making the issue and creating the PR!

If we were to add Koa support to the library directly that means we would have to have greater support for Koa in our docs and possibly samples just like we do for Express and Lambda.

At this time, Koa is not a focus for us so it's not a good idea to add it directly right now.

But since you already wrote the code though to support it, like you said you can make it a separate package as a framework plugin.

All you have to do is to export it as a plugin like so:

// name this export whatever
export const koa: Plugin<{}, {}> = app => {
  app.frameworks.koa = new Koa()
  return app
}

Then have it deployed as a npm package with actions-on-google as a peer dependency.

A developer would then just need to require the plugin package and app.use it.

const { dialogflow } = require(`actions-on-google`)
const { koa } = require(`actions-on-google-plugin-koa`) // or any package name you want
const Koa = require('koa')

const app = dialogflow().use(koa)

app.intent('Default Welcome Intent', conv => {
  conv.ask('How are you?')
})

const koaApp = new Koa()
koaApp.use(app)
koaApp.listen(3000)

Actually, in the v2 alpha, we wrote an example of how something could like here.

Canain avatar Mar 25 '19 20:03 Canain

came here looking for a generic solution that would allow me to pass in the response body / headers / status code myself and respond back myself too.

there are quite many framework out there right now that is widely supported and dosen't even have/use NodeJS IncommingRequest and instead operates on standard web Request/Response using respondWith(response) for instance or just return return new Response('hello world')

so i would like to have something as darn low level api as possible that dose not even handle any network traffic/api calls at all, and instead lets me do it myself somehow

jimmywarting avatar May 15 '23 00:05 jimmywarting