如何将Dialogflow与Django(Python)集成? [英] How to integrate Dialogflow with 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:
- 我知道我可以使用以下软件包进行操作: https://github.com /dialogflow/dialogflow-python-client-v2
-
我为Webhook添加了一个URL,现在这仅在本地有效,如下所示:
- 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-endpoint
和view
呈现它,以显示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
andview
for displaying purpose of your html file saybot.html
. - For dialogflow I first suggest you to build a
dialogflow
agent
as per you requirement. - for webhook of
agent
provided by yourdjangoserver
which is routed withlocaltunnel's
public IP
(for developement purpose use localtunnel like ngrok to yourdjango's
server
) - then add this link to
fulfillment
ofagent
.
嘿,您可以参考 LINK 使用它,您只需要
Hey you can refer this LINK using that you just need to
- 创建一个
url-endpoint
和view
说/chatbot
它将接受您通过bot通过AJAX
请求发送的文本.然后将此text
传递给链接中上述函数中的参数texts
.但是请对该功能进行一些更改,例如不打印fulfillment text
就将其返回. - 然后在
url-endpoint
/chatbot
中,返回该链接中该函数的响应,作为fulfillmentText
返回. - 如果要使用数据库的某些数据,则可以将
django-models
创建为普通数据库中的表,为此请检查
- Create one
url-endpoint
andview
say/chatbot
which will accepts your text send by bot byAJAX
request. Thistext
is then passes to parametertexts
in that above functions in link. But make some changes in that functions like without printingfulfillment text
just return it. - Then in above
url-endpoint
/chatbot
return the response asfulfillmentText
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 usingmodels.objects.all()
etc.
这篇关于如何将Dialogflow与Django(Python)集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!