【问题标题】:How to work with node.js and Dialogflow如何使用 node.js 和 Dialogflow
【发布时间】:2018-06-01 12:52:33
【问题描述】:

您能告诉我如何通过 node.js 使用 Dialogflow。我在哪里可以找到信息?

例如,这里我在 Python 中找到了一个示例,但是如何在 node.js 中进行相同的操作?

Python 代码:

from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import apiai, json
updater = Updater(token='ВАШ API ТОКЕН') # Токен API к Telegram
dispatcher = updater.dispatcher

def startCommand(bot, update):
    bot.send_message(chat_id=update.message.chat_id, text='Привет, давай пообщаемся?')
def textMessage(bot, update):
    request = apiai.ApiAI('ВАШ API ТОКЕН').text_request() # Токен API к Dialogflow
    request.lang = 'ru' # На каком языке будет послан запрос
    request.session_id = 'BatlabAIBot' 
    request.query = update.message.text 
    responseJson = json.loads(request.getresponse().read().decode('utf-8'))
    response = responseJson['result']['fulfillment']['speech'] 

    if response:
        bot.send_message(chat_id=update.message.chat_id, text=response)
    else:
        bot.send_message(chat_id=update.message.chat_id, text='Я Вас не совсем понял!')

start_command_handler = CommandHandler('start', startCommand)
text_message_handler = MessageHandler(Filters.text, textMessage)

dispatcher.add_handler(start_command_handler)
dispatcher.add_handler(text_message_handler)

updater.start_polling(clean=True)

updater.idle() 

【问题讨论】:

    标签: python node.js dialogflow-es


    【解决方案1】:

    您引用中的示例需要 apiai(第二行)。一个好的起点是寻找这些库以及它们是如何工作的。他们通常有示例代码和/或对示例的引用。

    看看https://github.com/dialogflow/dialogflow-nodejs-clienthttps://github.com/dialogflow/dialogflow-nodejs-client-v2

    快速在线搜索“dialogflow node.js”会提供大量示例,包括 Youtube 形式、Medium 文章或其他教程。

    【讨论】:

      【解决方案2】:

      这里是Beginner's guide to creating Chatbots using Dialogflow

      按照指南,您将能够创建像repofinder 这样的机器人。源代码在github 上提供。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-12-12
        • 1970-01-01
        • 1970-01-01
        • 2021-09-16
        • 2020-12-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多