BotHub CLI
This package provides a command line interface to BotHub.Studio service.
Installation
bothub-cli
is an unified tool to manage your chatbot project.
To install bothub-cli
on virtualenv
:
$ pip install bothub-cli
or, if you are not work on virtualenv
:
$ sudo pip install bothub-cli
The bothub-cli
package works on python2 and python3(recommended) both.
Getting Started
Before using bothub-cli
, you need to tell it about your BotHub.Studio credentials.
$ bothub configure
Username: myuser
Password: mysecret
Then it stores access token on ~/.bothub
directory.
To start build a new chatbot:
$ mkdir mybot
$ cd mybot
$ bothub init
Project name: mybot
Now you have a starter echo bot running on BotHub.Studio server:
.
|-- bothub
| |--bot.py
| `--__init__.py
|-- bothub.yml
|-- requirements.txt
`-- tests
You need to configure channel to use.
$ bothub channel add telegram --api-key=<my-api-key>
$ bothub channel add facebook --app-id=<app-id> --app-secret=<app-secret> \
--page-access-token=<page-access-token>
$ bothub channel add slack --client-id=<client-id> --client-secret=<client-secret) \
--signing-secret=<signing-secret>
$ bothub channel add kakao
Now, try talk to your chatbot.
Modify bot.py
for your purpose.
# -*- coding: utf-8 -*-
from bothub_client.bot import BaseBot
from bothub_client.messages import Message
from bothub_client.decorators import channel
class Bot(BaseBot):
"""Represent a Bot logic which interacts with a user.
BaseBot superclass have methods belows:
* Send message
* self.send_message(message, chat_id=None, channel=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)
When you omit user_id and channel argument, it regarded as a user
who triggered a bot.
"""
@channel()
def default_handler(self, event, context):
message = Message(event).set_text('You says: {}'.format(event['content']))\
.add_quick_reply('Yes')\
.add_quick_reply('No')
self.send_message(message)
and deploy it.
$ bothub deploy
Usage
Usage: bothub [OPTIONS] COMMAND [ARGS]...
Bothub is a command line tool that configure, init, and deploy bot codes
to BotHub.Studio service
Options:
--help Show this message and exit.
Commands:
channel Setup channels of current project
clone Clone existing project
configure Setup credentials
deploy Deploy project
init Initialize project
logs Show error logs
ls List projects
new Create new project
nlu Manage project NLU integrations
property Manage project properties
rm Delete a project
test Run test chat session
Setup
Authorize an user and get access token.
$ bothub configure
Project management
Initialize project on current directory or new directory. Create an initial echo chatbot.
$ bothub init
Or you can use new command
$ bothub new
Clone an existing project.
$ bothub clone <project-name>
Deploy current project.
$ bothub deploy
Show project list.
$ bothub ls [-l]
Delete a project.
$ bothub rm <project-name>
Show error logs.
$ bothub logs
Run current project on local machine for test.
$ bothub test
Channel management
List of channels for current project.
$ bothub channel ls
Add a channel for current project.
$ bothub channel add telegram --api-key=<api-key>
$ bothub channel add facebook --app-id=<app-id> --app-secret=<app-secret>\
--page-access-token=<page-access-token>
$ bothub channel add slack --client-id=<client-id> --client-secret=<client-secret) \
--signing-secret=<signing-secret>
$ bothub channel add kakao
Remove a channel from current project.
$ bothub channel rm <channel-name>
NLU management
List of NLU integration for current project.
$ bothub nlu ls
Add a NLU integration for current project.
$ bothub nlu add apiai --api-key=<api-key>
Remove a NLU integration from current project.
$ bothub nlu rm <nlu>