如何将Dialogflow与Django(Python)集成? [英] How to integrate Dialogflow with Django (Python)?

查看:89
本文介绍了如何将Dialogflow与Django(Python)集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Dialogflow开发一个助手(机器人),并且我有一个Django项目,我必须在其中提取数据,然后通过该机器人公开它,该数据将存储在本地平台中.

I'm developing an assistant (bot) with Dialogflow, and i have this Django project where I have to extract data and then expose it through the bot, this is going to be stored in a local platform.

我以前使用Dialogflow及其集成,但是使用Node.js和Javascript以及Django(python)是一个全新的挑战,我感到困惑.

I worked with Dialogflow and it's integration before but with Node.js and Javascript, with Django (python) is a brand new challenge and I'm confused.

直到现在我有以下内容:

Until now I have the following:

  • I know I can do it with this package: https://github.com/dialogflow/dialogflow-python-client-v2
  • I add a url for a webhook, right now this works locally only, like this:

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
import dialogflow


@csrf_exempt
def webhook(request):
    return HttpResponse('Works like a charm!')

,在urls.py中,我有:

and in urls.py I have:

url(r'^webhook$', views.webhook, name='webhook')

仅此而已,我不知道该怎么办,我被封锁了,我也不知道如何进行整合以及缺少什么建议?

And that's all I don't know how to proceed after this, I'm blocked and I don't know how yto make the integration and what's missing, any recommendations?

推荐答案

步骤

  • 为聊天机器人UI制作一个html文件,方法是用一个url-endpointview呈现它,以显示html文件的用途,例如bot.html.
  • 对于对话流,我首先建议您根据需要构建dialogflow agent.
  • 用于由djangoserver提供的djangoserver提供的agent的Webhook,并通过localtunnel's public IP路由(出于开发目的,请使用本地隧道,例如
  • Make one html file for your chatbot UI by rendering it with one url-endpoint and view for displaying purpose of your html file say bot.html.
  • For dialogflow I first suggest you to build a dialogflow agent as per you requirement.
  • for webhook of agent provided by your djangoserver which is routed with localtunnel's public IP (for developement purpose use localtunnel like ngrok to your django's server)
  • then add this link to fulfillment of agent.

嘿,您可以参考 LINK 使用它,您只需要

Hey you can refer this LINK using that you just need to

  • 创建一个url-endpointview/chatbot 它将接受您通过bot通过AJAX请求发送的文本.然后将此text传递给链接中上述函数中的参数texts.但是请对该功能进行一些更改,例如不打印fulfillment text就将其返回.
  • 然后在url-endpoint /chatbot中,返回该链接中该函数的响应,作为fulfillmentText返回.
  • 如果要使用数据库的某些数据,则可以将django-models创建为普通数据库中的表,为此请检查
  • Create one url-endpoint and view say /chatbot which will accepts your text send by bot by AJAX request. This text is then passes to parameter texts in that above functions in link. But make some changes in that functions like without printing fulfillment text just return it.
  • Then in above url-endpoint /chatbot return the response as fulfillmentText return by that function in link.
  • If you wanna use some data of your databases then you can create django-models as tables in normal database, for that check the models - docs. then you can access data by using models.objects.all() etc.

这篇关于如何将Dialogflow与Django(Python)集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆