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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何加载JNI。具有依赖项的动态库文件,但未获得未满足的链接错误?   java ResultSet元数据未返回第一行   无法从java xml解析器中的当前节点获取节点列表   java如何从for循环值创建单个数组   java如何在没有arrayList的情况下查找对象   java ItemizedOverlayWithFocus在聚焦osmdroid时显示另一个覆盖   java使用迭代器进行“向下”迭代的优雅方式   java如何使用OnListItemClick为listview和AlertDialog使用单独的arraylist?   arraylist读取txt文件Java中存储的数组   javascript IE 11与RicoLive Grid 2.2框架不兼容   java我能得到水豚的maven依赖性吗?   简单Escp Java:PrintPreviewPane在JDK7中不起作用   java取出给定字符串的一部分,并将所取部分作为变量返回?   java如何替换“instanceof”函数中的变量   来自url的Java utf8编码   java方法获取类Gregorianalendar?   安卓如何在java 7中使用AndroidStudio和DDMS监视器   java测试在JUnit4下运行,但不是在JUnit5下运行-编译干净,但执行0测试   java无法使用Azure服务总线发送消息