简体   繁体   English

在 Node.js 上的打字稿文件之间拆分 Actions-on-Google 意图

[英]Splitting Actions-on-Google intents between typescript files on Node.js

In my src/index.ts file on firebase functions for my dialogflow + google actions I have code which looks like the below:在我的 dialogflow + google 操作的 firebase 函数的src/index.ts文件中,我的代码如下所示:

import * as functions from 'firebase-functions';
import { dialogflow, Suggestions } from 'actions-on-google';

const app = dialogflow({debug: true})
app.intent('Default Welcome Intent', conv => {
conv.ask('Question')
});

exports.dialogflowFulfillment = functions.https.onRequest(app);

I would like to split each intent into its own TS file (as I intend to have quite a few), but am lost as to how to export each intent from seperate .ts files to interact with app我想将每个意图拆分成它自己的 TS 文件(因为我打算有很多),但是我不知道如何从单独的.ts文件中导出每个意图以与app交互

Any ideas would be appreciated任何想法,将不胜感激

Here's one organization that seems sane to me as a TypeScript programmer to have a set of TypeScript files that each have access to the app to add their own intents.这是一个在我看来作为 TypeScript 程序员的组织,它拥有一组 TypeScript 文件,每个文件都可以访问app以添加自己的意图。 I've avoided side effects outside index.ts and circular dependencies among modules.我避免了index.ts之外的index.ts和模块之间的循环依赖。 (Maybe people familiar with Dialogflow or Actions on Google will have their own recommendations.) (也许熟悉 Dialogflow 或 Actions on Google 的人会有自己的建议。)

// app.ts
import { dialogflow } from 'actions-on-google';

export function createApp() {
    return dialogflow({debug: true});
}
export type App = ReturnType<typeof createApp>;

// intent1.ts
import { App } from "./app";

export function addIntent1(app: App) {
    app.intent('Default Welcome Intent', conv => {
        conv.ask('Question')
    });        
}

// index.ts
import * as functions from 'firebase-functions';
import { createApp } from './app';
import { addIntent1 } from './intent1';

const app = createApp();
addIntent1(app);

exports.dialogflowFulfillment = functions.https.onRequest(app);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM