Skip to main content

Bot client for rocketchat BotBridgeApp

Project description

This is a RocketChat bot library using an app bridge to create bots with interactive elements such as buttons.

preview

☝ Important

In addition to this description, be sure to see an example of a bot on how to send and build data to send

Usage

  • First, you need to install this application on your rocket chat server.
  • Then go to the admin settings -> applications -> BotBridge -> and copy the POST webhook address
  • In the Controlled bots settings field, enter the nickname of the bot user you want to use. Or leave it blank if you want to use the standard @bbot.bot account automatically created for the application
  • install package with pip install rocketchat-bot-simple-app-bot and import this in your project
    from rocketchat_bot_app_bridge.RCBot import RCBot
    from rocketchat_bot_app_bridge.definitions.application import IButton
    from rocketchat_bot_app_bridge.definitions.message import IMessage
    from rocketchat_bot_app_bridge.definitions.user import IUser
    
  • Now you can create a bot instance.
    bot = RCBot() If you want to use a custom bot account, then after adding it in the application settings, pass its username like this
    bot = RCBot(account_username='testbot')
  • Since communication is carried out in both directions between the RocketChat application and this bot server. Here a web server will be configured on the default port 3228
    You can specify your port in the environment variable
    export BOT_PORT=12345 Also you can pass the port when creating the bot RCBot (port=12345) [[[подробнее в файле примаера добавитьссылку]]]
  • Also, the link you copied to the POST webhook must be passed to the APP_ENDPOINT environment variable
    export APP_ENDPOINT=http://rocket.chat/api/apps/private/2c3927404e41/sab7/webhook
    
    Or when created in the same way as the port. more details here.
  • Now there are several decorators available to you that you can use on your functions.
    @bot.on_new_message
    def new_message(message: IMessage = None):
        pass
    
    @bot.on_button_click(action='btn1-action')
    def click_button(action, user: IUser = None, source_message: IMessage = None):
        pass
    
    @bot.on_button_click(startswith='btn-danger-')
    def click_button(action, user: IUser = None, source_message: IMessage = None):
        pass
    
    @bot.hear(pattern=r"Why (?P<phrase>.*)\??")
    def answer_the_question(message: IMessage, phrase):
        pass
    
  • Finally, you need to start the server and wait loop.
    bot.run()
    
    while True:
        time.sleep(300)
    
    P.S. Eliminate the need for loop in my todo for easier work
  • After launching, there will be a line in the log saying that the server is running.
    | INFO     | run:57 - Listen on **http://0.0.0.0:3228/** copy this(or service ip for kubernetes) to RocketChat app settings
    

You need to specify the address of the server on which the bot is running in the rocket chat settings as a backend address.
Instead of 0.0.0.0, there should be one of your server addresses, which will be available for rocket chat. Eg. Service name in docker-compose or kubernetes

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

rocketchat_bot_simple_app_bot-0.1.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rocketchat_bot_simple_app_bot-0.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file rocketchat_bot_simple_app_bot-0.1.0.tar.gz.

File metadata

  • Download URL: rocketchat_bot_simple_app_bot-0.1.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.5

File hashes

Hashes for rocketchat_bot_simple_app_bot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cf902e4b87196db9f6bea0bf5fa20e788f668fec9b4709ac63752a158c425161
MD5 4811f851257b4099f19f04ff55dff416
BLAKE2b-256 8652abd4e777ff17e93fc42f45ab685e533c9a735224b9a31996e4c4a9341243

See more details on using hashes here.

File details

Details for the file rocketchat_bot_simple_app_bot-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rocketchat_bot_simple_app_bot-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.5

File hashes

Hashes for rocketchat_bot_simple_app_bot-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df4b5ac7550ba6a01d1ac88356a34dfbb9cefde36922d099e6dd8a1aa7cedb4c
MD5 281bc9c5b93087c88b090399ed37290e
BLAKE2b-256 69d7d85cb3401897f3de07d706f11fcbcbfbcf7288882b39d709ce80de0359e6

See more details on using hashes here.

Supported by

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