Bots

Simple and powerful Python library that makes it easy to build bots on server-side.

Example

This bot replies with message 'Hello world human! Send "Give me a file" to me' if receives any text different than 'Give me a file'.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json
import requests
import os

from imbee import IMbeeAccount, IMbeeConnection, IMbeeMessage

IMBEE_USER = os.environ['IMBEE_USER'] # Bot
IMBEE_DOMAIN = os.environ['IMBEE_DOMAIN']
IMBEE_PASSWORD = os.environ['IMBEE_PASSWORD']
IMBEE_SERVER = os.environ['IMBEE_SERVER']

def on_message(msg):
    if msg.action == 'SEND_MESSAGE':
        if msg.text == 'Give me a file':
            url = 'https://filestorage.imbee.es/dj29048524895j.zip'
            name = 'Confidential document'
            msg_reply = msg.reply(FileContent(url, name))
        else:
            msg_reply = msg.reply(TextContent('Hello world human! Send "Give me a file"'))

        msg_reply.send()

if __name__ == '__main__':
    account = IMbeeAccount(IMBEE_USER, IMBEE_DOMAIN, IMBEE_PASSWORD)

    imbee = IMbeeConnection(account)
    imbee.on_message = on_message
    imbee.connect(IMBEE_SERVER)
    imbee.process(block=True)

Last updated