简体   繁体   English

如何在NodeJS中构建Messenger Messenger?

[英]How can i structure my Messenger Chatbot in NodeJS?

I'm currently working on a NodeJS powered Messenger Chatbot, using Wit.ai and Firebase, hosted on Heroku. 我目前正在使用由Heroku托管的Wit.ai和Firebase开发基于NodeJS的Messenger Chatbot。 I've followed an udemy course to learn the basics about chatbots and I've made a decent chatbot imo. 我已经完成了一个课程的学习,以学习有关聊天机器人的基础知识,并且制作了一个不错的聊天机器人imo。

But, as I'm adding new features, I don't really know how to correctly structure and organize my project. 但是,当我添加新功能时,我真的不知道如何正确地组织和组织我的项目。 To be honest, I've currently have one big index.js file, of about 1 000 lines, because in the middle there is a giant Switch Case structure managing all of the intents a user can possibly have. 老实说,我目前有一个大的index.js文件,大约有1000行,因为中间有一个巨大的Switch Case结构,用于管理用户可能拥有的所有意图。

I'm also making nodejs modules with "exports.function" but it seems it's an old way to do and it doesn't solve my switch case problem. 我也在用“ exports.function”制作nodejs模块,但是这似乎是一种古老的方法,并且不能解决我的切换用例问题。

Do you any suggestions to solve my structure issue ? 您对解决我的结构问题有什么建议吗?

I've found this post suggesting some structures but I don't know if it can really fit a Chatbot project. 我发现这篇文章暗示了一些结构,但我不知道它是否真的适合Chatbot项目。

Thanks for you time, have a nice day. 谢谢你的时间,祝你有美好的一天。

就个人而言,我建议尝试使用node-red,因为如果您要连接许多API,则更容易可视化。

I've currently have one big index.js file, of about 1 000 lines, because in the middle there is a giant Switch Case structure managing all of the intents a user can possibly have 我目前有一个大的index.js文件,大约有1000行,因为中间有一个巨大的Switch Case结构,用于管理用户可能拥有的所有意图

This is clearly to avoid. 这显然是可以避免的。 In these conditions the code is hardly readable and untestable. 在这种情况下,代码很难被读取和测试。 I wrote an article on how to structure a Node webhook for a chatbot . 我写了一篇文章, 介绍如何为聊天机器人构建Node webhook Jump to the section Chatbot Webhook to have an example on the implementation. 跳转至Chatbot Webhook部分以获取实现示例。 It is for a Dialogflow chatbot but you won't be lost as Wit.ai and Dialogflow have many similarities. 它是用于Dialogflow聊天机器人的,但您不会因为Wit.ai和Dialogflow有很多相似之处而迷失方向。

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

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