bothub.studio服务的cli工具
bothub-cli的Python项目详细描述
此包为Bothub.studio服务提供命令行接口。
安装
要安装bothub cli:
$ pip install bothub-cli
或者,如果您没有安装在virtualenv:
$ sudo pip install bothub-cli
bothub cli包对python2和3都有效。
开始
在使用bothub cli之前,您需要告诉它您的Bothub.studio凭据。
$ bothub configure Username: myuser Password: mysecret
然后它将访问令牌存储在~/.bothub目录中。
开始构建新机器人:
$ mkdir mybot
$ cd mybot
$ bothub init
Project name: mybot
现在您有了一个初级回声机器人:
. |-- bothub | |-- bot.py | `-- __init__.py |-- bothub.yml |-- requirements.txt `-- tests
根据您的需要编辑下面的bot.py。
# -*- coding: utf-8 -*-from__future__import(absolute_import,division,print_function,unicode_literals)frombothub_client.botimportBaseBotfrombothub_client.decoratorsimportchannelclassBot(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) * Channel Handler from bothub_client.decorators import channel @channel('<channel_name>') def channel_handler(self, event, context): # Handle a specific channel message * Command Handler from bothub_client.decorators import command @command('<command_name>') def command_handler(self, event, context, args): # Handle a command('/<command_name>') * Intent Handler from bothub_client.decorators import intent @intent('<intent_id>') def intent_result_handler(self, event, context, answers): # Handle a intent result # answers is a dict and contains intent's input data { "<intent slot id>" : <entered slot value> ... } """@channel()defdefault_handler(self,event,context):
部署它。
$ bothub deploy
您还需要配置要使用的通道。
$ bothub channel add telegram --api-key=<my-api-key>
用法
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 nlu Manage project NLU integrations property Manage project properties rm Delete a project test Run test chat session
设置
授权用户并获取访问令牌。
$ bothub configure
项目管理
初始化当前目录上的项目。创建echo chatbot代码。
$ bothub init
部署当前项目。
$ bothub clone <project_name><克隆现有项目。
$ bothub deploy
项目列表。
$ bothub ls
删除项目。
$ bothub rm <project_name>
显示错误日志。
$ bothub logs
在本地计算机上运行当前项目以进行测试。
$ bothub test
渠道管理
当前项目的频道列表。
$ bothub channel ls
为当前项目添加频道。
$ 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 rm <channel>
NLU集成管理
当前项目的NLU(自然语言理解)集成列表。
$ bothub nlu ls
为当前项目添加NLU集成。
$ bothub nlu add apiai --api-key=<api_key>
从当前项目中删除NLU集成。
$ bothub nlu rm <nlu>
许可证
apache许可证2.0