【问题标题】:Dialogflow endpoint type in typescript打字稿中的Dialogflow端点类型
【发布时间】:2019-08-07 14:00:44
【问题描述】:

我已经在 Typescript 中为 Dialogflow 实现了一个 webhook,我希望我的 Google 端点仅支持 Dialogflow SDK 对象。目前我的控制器看起来像这样:

import {dialogflow, DialogflowConversation} from "actions-on-google";

export class GoogleController {
  public endpoint: any;

constructor() {
  this.endpoint = dialogflow();
  this.endpoint.intent("Welcome", (conv: DialogflowConversation) => {
    return conv.ask("Hey There");
  });
};

目前我已将端点设为任何类型,但我想将其更改为 Dialogflow 对象。我尝试从 SDK 导入 DialogflowApp 对象,但这些似乎不起作用。它们与 dialogflow() 调用返回的对象不匹配,或者接口没有 .intent 函数。

有谁知道如何做到这一点?

【问题讨论】:

    标签: typescript dialogflow-es actions-on-google


    【解决方案1】:

    在 VSCode 中打开一个项目,我写道:

    import { dialogflow } from 'actions-on-google'
    
    const endpoint = dialogflow()
    

    将鼠标悬停在endpoint 上,VSCode 会显示一些关于变量的元数据:

    const endpoint: OmniHandler & BaseApp & DialogflowApp<{}, {}, Contexts, DialogflowConversation<{}, {}, Contexts>>

    也许您的 DialogflowApp 声明需要泛型,或者您可以直接复制该字符串。

    【讨论】:

    • 是的,声明需要泛型。我通过创建一个扩展您提到的字符串的空接口对其进行了一些改进,现在我可以使用我的 DialogflowEndpoint 接口而不是长字符串。
    猜你喜欢
    • 2022-12-05
    • 2021-11-26
    • 2020-10-12
    • 2021-06-03
    • 2021-05-08
    • 2019-09-23
    • 1970-01-01
    • 2018-08-12
    • 1970-01-01
    相关资源
    最近更新 更多