使用 Dialogflow Conv.Data 或 Conv.User.Storage 的简单计数器
Simple Counter using Dialogflow Conv.Data or Conv.User.Storage
我希望使用 google.
的操作在 firebase 函数的对话中创建一个超级简单的计数器
documentation 推荐:
app.intent('Default Welcome Intent', conv => {
conv.data.someProperty = 'someValue'
})
然而,typescript 无法将 conv.data 之后的任何类型的点符号识别为值,并且不允许部署代码。
然而,据我所知,使用
app.intent('Default Welcome Intent', conv => {
conv.data["someProperty"] = 1;
})
可以,但似乎不允许计算 int...
我试过:
conv.data['currentIndex'] = parseInt(conv.data['currentIndex']) + 1;
conv.data['currentIndex'] = parseInt(conv.data['currentIndex'])++;
conv.data['currentIndex'] += 1;
我觉得我在这里缺少一些非常基本的东西。
谢谢
我认为您需要明确指定要使用的变量类型。
尝试像这样定义接口:
//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
})
我希望使用 google.
的操作在 firebase 函数的对话中创建一个超级简单的计数器documentation 推荐:
app.intent('Default Welcome Intent', conv => {
conv.data.someProperty = 'someValue'
})
然而,typescript 无法将 conv.data 之后的任何类型的点符号识别为值,并且不允许部署代码。
然而,据我所知,使用
app.intent('Default Welcome Intent', conv => {
conv.data["someProperty"] = 1;
})
可以,但似乎不允许计算 int...
我试过:
conv.data['currentIndex'] = parseInt(conv.data['currentIndex']) + 1;
conv.data['currentIndex'] = parseInt(conv.data['currentIndex'])++;
conv.data['currentIndex'] += 1;
我觉得我在这里缺少一些非常基本的东西。
谢谢
我认为您需要明确指定要使用的变量类型。
尝试像这样定义接口:
//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
})