Skip to main content

Dialogflow Webhook utility package

Project description

Pylogflow

Python library for Dialogflow webhook. / Biblioteca de python para webhooks en Dialogflow

Content Table / Tabla de contenido

  • Language / Idioma
    • English
      • Description
      • Requirements
      • Installation
      • Usage
      • Support me
    • Español
      • Descripcion
      • Requisitos
      • Instalación
      • Uso
      • Apoyar

English documentation

Description

The purpouse of pylogflow is allow people to do chatbots easier without knowing how dialogflow works, and let proggrammer just focus on the process that they want to do (I think that their javascript library is complex in further level and i love python).

This library can manage responses(messages) and intents in this version, in next versions i'll add context management and easy parameters management (just i make it for Actions on Google, i have to do for generic responses).

Requirements

  • Python 3
  • Python pip

Installation

pip install pylogflow

Usage

Before start

To start using pylogflow you must know how to setup a web server with python, read this if you dont know how to start

In examples below i'll use flask that is a web framework on python, it's really easy to use, you can learn more about it here.

Intent Handling

If you have some intents in your Dialogflow agent that points to webhook you have to manage them, so pylogflow includes intent handling that makes it easy.

Suppose that you have an intent named "Test" and you want to handle in webhook, you will do something like this.

from pylogflow import IntentMap
from flask import request, jsonify

app = flask.Flask(__name__)

# We will receive POST request when webhook is called
@app.route('/', methods=['POST'])
def webhook():
    # Send request as a json dictionary, result must be a dictionary
    result = intentMap.execute_intent(request.json)
    # Parse result into json response format
    return jsonify(result)

# Intent 'Test' function
# They must receive a request in dictionary format.
def intentTest(req):
    # Simpliest response to dialogflow
    return {'fulfillmentText': 'This is a response from webhook'}

# Intent Map for handle intents
intentMap = IntentMap()
# add method appends new intent with their function
# first parameter must be the Dialogflow intent name, second is the function name
intentMap.add('Test', intentTest)

# flask run configuration
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

The code above it's the simpliest way to handle an intent in webhook, i just send request in dictionary format to intentMap with 'execute_intent' function, and then get response with 'get_response' function and return as json with jsonify feature from flask, the rest of the code is to make a function that build response and then return it, below of all must create intentMap object and then add respective intent with their respective name(must be same as we set in Dialogflow).

Responses (messages)

There are some responses that we can send to dilogflow, this version can make Generic responses and Google Assistant responses.

Agent Responses

Agent class can handle generic text and card responses( i don't recomend card responses for now, i'm searching why Google Assistant doesn't handle that cards and get error, if you want to add cards for Google, use GoogleResponse instead).

Below i'll use same example to explain agent usage, we have to focus on 'intentTest' function, and remember to import Agent.

from pylogflow import IntentMap, Agent
from flask import request, jsonify

app = flask.Flask(__name__)

# Main Webhook route
@app.route('/', methods=['POST'])
def webhook():
    result = intentMap.execute_intent(request.json)
    return jsonify(result)

def intentTest(req):
    # We create an Agent object
    agent = Agent()
    # We can add messages
    agent.add_message("Hi")
    agent.add_message("How are you?")
    # Or cards (just one recommended)
    agent.add_card("title","subtitle","imageURL","buttonName", "buttonURL")
    # Then, we return the response in dictionary format
    return agent.get_response()

# Intent Map for handle intents
intentMap = IntentMap()
intentMap.add('Test', intentTest)

# flask run configuration
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

In this case, in 'intentTest' function we have to create agent, after that, we can add messages, cards and then send response back, it's really easy.

Google Asisstant

Advice

My english is not good at all, if i got an error correct me please.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylogflow-0.1.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pylogflow-0.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file pylogflow-0.1.tar.gz.

File metadata

  • Download URL: pylogflow-0.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4

File hashes

Hashes for pylogflow-0.1.tar.gz
Algorithm Hash digest
SHA256 7320339012ca52341da1094e0c5545c98e99929ac933f864307864629dd84895
MD5 a4815af9948903ccfeed2792e66ca5e1
BLAKE2b-256 6495dbf093ef628ea71feeef4da8d0d2b7e039677da8b48f1baf4a502649215c

See more details on using hashes here.

File details

Details for the file pylogflow-0.1-py3-none-any.whl.

File metadata

  • Download URL: pylogflow-0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4

File hashes

Hashes for pylogflow-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2cb8085af7b8ddcd4399e3f9c7fa270a0fd2dbc2efc7a77af8f5c7dd6d4f59a0
MD5 ca8674396a5ad985a3dba0c135a9309b
BLAKE2b-256 554064bcb0510489db342f0c1a6802e6759f33d5eabc6a6f0e127027529ea8b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page