node.js - 使用 Dialogflow Conv.Data 或 Conv.User.Storage 的简单计数器
问题描述
我正在寻找使用谷歌操作在firebase函数中的对话中创建一个超级简单的计数器。
文档建议:
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 TS 示例上的操作。
推荐阅读
- python - 图像转换的单应性不能正常工作
- tfs - TFS Microsoft Visual Studio Scrum 2013.4 原始模板
- java - 使用 mockito 检查是否仅使用特定参数调用了一次方法
- java - ArrayList 和 CircularArrayList 之间的主要区别是什么
- ruby-on-rails - 希望我的书签操作能够工作并保持在同一页面上而不是呈现新页面,不确定正确的 link_to 助手
- spring-webflux - 我什么时候使用 Mono.flatMapIterable 和 Mono.flapMapMany?
- discord - discord.py-rewrite - 如何在 cogs 中使用自定义检查?
- prolog - 从给定的连接中找到 2 个点之间的路径
- c# - 仅在主/副显示器上设置壁纸
- hibernate - Spring-jpa 使用 spring-aop 动态代理?