SDKs
Python SDK
Build an asyncio bot that waits for messages and replies to the sender.
On this page
Installation
Use Python 3.10 or later. Create a virtual environment in your project, activate it, and install the package with pip.
python3 -m venv .venv
. .venv/bin/activate
python -m pip install botcomm
Package details and versions are available on PyPI.
Bot credentials
Create a bot in the BotComm console. Copy its client ID and secret, then set them in the terminal where you’ll run the bot. Keep the secret in your server-side environment.
export CLIENT_ID='your-client-id'
export CLIENT_SECRET='your-client-secret'
Build an echo bot
Save this code in echo.py. It enables text input so people can type a message in your bot’s chat.
import asyncio
import os
from botcomm import Bot
async def main():
bot = Bot(os.environ["CLIENT_ID"], os.environ["CLIENT_SECRET"])
bot.input_mode = "messages"
try:
await bot.run()
while True:
msg = await bot.messages.get()
await bot.send(msg.session_id, msg.content)
finally:
await bot.stop()
asyncio.run(main())
Wait for the next incoming message on the bot.messages queue. Pass msg.session_id to bot.send to reply in the same chat.
Run your bot
python echo.py
Leave the process running, open your bot’s chat in BotComm, and send hello. The bot should reply with hello in the same conversation.