gpt4 book ai didi

node.js - 使用 Dialogflow Conv.Data 或 Conv.User.Storage 的简单计数器

转载 作者:太空宇宙 更新时间:2023-11-03 22:58:49 27 4
gpt4 key购买 nike

我希望使用 Google 操作在 Firebase 函数的对话中创建一个 super 简单的计数器。

documentation推荐:

app.intent('Default Welcome Intent', conv => {
conv.data.someProperty = 'someValue'
})

但是,typescript 无法将 conv.data 后面的任何类型的点符号识别为值,并且不允许部署代码。

但是,据我所知,使用

app.intent('Default Welcome Intent', conv => {
conv.data["someProperty"] = 1;
})

可以,但似乎不允许计算整数...

我已经尝试过:

conv.data['currentIndex'] = parseInt(conv.data['currentIndex']) + 1;


conv.data['currentIndex'] = parseInt(conv.data['currentIndex'])++;


conv.data['currentIndex'] += 1;

我觉得我在这里错过了一些非常基本的东西。

谢谢

最佳答案

我认为您需要明确指定要使用的变量类型。

尝试定义如下接口(interface):

//use this in conv.data

interface ConvData {
counter?: number
}

// use in conv.user.storage
interface UserStorage {
location?: string
name?: string
}

并将应用程序初始化为:

const app = dialogflow<ConvData, UserStorage>({ debug: true })

然后使用

app.intent('Default Welcome Intent', conv => {
conv.data.counter = 1
})

引用:Actions on Google TS sample .

关于node.js - 使用 Dialogflow Conv.Data 或 Conv.User.Storage 的简单计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53231680/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com