Skip to main content

A simple package for interfacing with Dialogflow

Project description

Affability

Affability allows for an easy utilization of Google's DialogFlow for natural language understanding. It allows for calling a single function and returning the result from Dialogflow as a class containing all the pertinent data such as detected intent. Communicating with Dialogflow through Affability trades-off features and customizability for simplicity and conciseness.

This can be utilized to understand commands and then perform the relevant tasks based from the detected intent. Affability is ultimately designed to make it easy to integrate DialogFlow in other standalone projects.

Dependencies

As of v1.0.1, affability automatically installs dialogflow. Should speech recognition be needed, the SpeechRecognition pakage needs to be installed.

pip install SpeechRecognition

With an invalid argument, Affability throws an InvalidArgument exception, which requires importing it from the Google API Core exceptions:

from google.api_core.exceptions import InvalidArgument

Installation

pip install affability

Usage

The module can be imported as affability:

import affability

Using the understand function:

The understand function contains 5 parameters: text, credentials, projectID, languageCode, and sessionID. Text is text to be analyzed, credentials is the file path of the authentication key, projectID is the project ID, languageCode is the language, and sessionID is the session ID. All parameters are strings.

affability.understand('textToBeAnalyzed', 'filepath', 'projectIDname', 'en-US', 'me')

The understand function returns the results as an organizer class. This class contains detectedIntent, confidence, reply, action, requiredParamsPresent, and replyParams.

class organizer:
    def __init__(self, detectedIntent, confidence, reply, action, requiredParamsPresent, replyParams):
        self.detectedIntent = detectedIntent
        self.confidence = confidence
        self.reply = reply
        self.action = action
        self.requiredParamsPresent = requiredParamsPresent
        self.replyParams = replyParams

For example, to extract and print detected intent:

reply = affability.understand('textToBeAnalyzed', 'filepath', 'projectIDname', 'en-US', 'me')
print(reply.detectedIntent)

Affability throws the InvalidArgument exception when DialogFlow detects invalid arguments. To handle this, it is recommended to use the understand function in a try and except block:

try:
    reply = affability.understand('textToBeAnalyzed', 'filepath', 'projectIDname', 'en-US', 'me')
    # do something with reply
except InvalidArgument:
    # Handle invalid argument error

Sample usage

The sample.py file demonstrates the ease of communicating with Dialogflow through Affability.

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

affability-1.0.3.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

affability-1.0.3-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file affability-1.0.3.tar.gz.

File metadata

  • Download URL: affability-1.0.3.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3

File hashes

Hashes for affability-1.0.3.tar.gz
Algorithm Hash digest
SHA256 4b39599943c19c2724355dd0cb1d56f8b9bb68a94e9ae6f3b4b129f9ae7b8be7
MD5 10d4d95106c8e4dc28a3aac50760063f
BLAKE2b-256 dbac591226faf253955fab9d719f532a777eef0ef14e9a2049325e67561ab71d

See more details on using hashes here.

File details

Details for the file affability-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: affability-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3

File hashes

Hashes for affability-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 03b098cd8ce79cf4042838e73a4a603a1e72208810bb3ea5abe647e704021bec
MD5 2f7e393cfc04caa7da8f30d0e1556730
BLAKE2b-256 bc38f63c8facf741c041a7e47a229c580522090febb69d6478485c1911b93831

See more details on using hashes here.

Supported by

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