问题
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.
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!')
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?
回答1:
Steps
- 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
.
Hey you can refer this LINK using that you just need to
- 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.
来源:https://stackoverflow.com/questions/50921502/how-to-integrate-dialogflow-with-django-python