Skip to main content

Build serverless chatbot on BotHub.Studio

Project description

This package provide components to works with BotHub.Studio, which is a chatbot hosting service.

With bothub-cli, you can deploy a new chatbot with just four lines of commands.

Installation

To install bothub:

$ pip install bothub

The bothub package works on python2 and 3 both.

Getting Started

You can build a echo chatbot simply by subclassing BaseBot class and overriding handle_message method.

# -*- coding: utf-8 -*-

from bothub_client.bot import BaseBot

class Bot(BaseBot):
    """Represent a Bot logic which interacts with a user.

    BaseBot superclass have methods belows:

    * Send message
      * self.send_message(message, user_id=None, channel=None, extra=None)
    * Data Storage
      * self.set_project_data(data)
      * self.get_project_data()
      * self.set_user_data(data, user_id=None, channel=None)
      * self.get_user_data(user_id=None, channel=None)
      * self.nlu(vendor) -> NluClient

    When you omit user_id and channel argument, it regarded as a user
    who triggered a bot.
    """

    def handle_message(self, event, context):
        self.send_message(event['content'])

When a bot receives a message from an user, it triggers handle_message method with event and context object.

An event is a dict which contains following items:

content

A message text received.

channel

Which channel (messenger platform) sent a message.

sender

Who sent a message. {"id": <user-id>, "name": "<username>}

raw_data

A raw data itself messenger platforms offers.

You can respond to this message with various tools we provides.

Messaging

To send a message, use a self.send_message method with a message you want to send.

self.send_message('hello')

Most of case you can omit user_id and channel arguments or put values to those arguments to send a message to specific user rathan than whom sent a message to your bot.

NLU Integeration

If you registered NLU integration at BotHub.Studio, you can use nlu method to make a request.

There are two styles to request to NLU service. (eg. to use API.ai)

First, use event object to construct message and session_id.

def handle_message(self, event, context):
    response = self.nlu('apiai').ask(event=event)
    self.send_message(response.next_message)

Or, put explicit message and session_id by yourself.

def handle_message(self, event, context):
    response = self.nlu('apiai').ask(message='hello', session_id='customer1')
    self.send_message(response.next_message)

ask method returns a NluResponse class which contains attributes like:

raw_response

A raw response which NLU service returns.

action

A NluAction class object to identify intent and required parameters.

next_message

Next message text to respond NLU service recommend.

License

This package is licensed under AGPLv3 for non-commercial personal use. If you want to use this package for commercial use, please contact to bothub@bothub.studio.

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

bothub-0.1.10.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

bothub-0.1.10-py2.py3-none-any.whl (10.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file bothub-0.1.10.tar.gz.

File metadata

  • Download URL: bothub-0.1.10.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for bothub-0.1.10.tar.gz
Algorithm Hash digest
SHA256 d031a94a354c1769b6c2301f80aa177394fc100384e81062d8af046d2b272dcd
MD5 e04f8e7ef2897679d3fa2de3512b55ca
BLAKE2b-256 e788eda5c46f81488dba2092d5be35dac7e894b37400512af91c638399b8e6e1

See more details on using hashes here.

File details

Details for the file bothub-0.1.10-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for bothub-0.1.10-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ab6b4d1042feb1bfd4f80fd4a1c22777eed2ed0ba6c4ba8a43bb5c490520eca4
MD5 70d4432cf417c2c5199f0560df30ebb1
BLAKE2b-256 77239f1eec46228be175ec305d50ba3a49a331899696f315c87617183b267ece

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