webex-bot-core
A Webex Bot framework for rapid bot development with built-in RBAC, interactive scheduler, and Adaptive Card support.
Installation
Prerequisite
- Python >= 3.10
- A Webex bot access token — create a bot at developer.webex.com
Install
pip install webex-bot-core
bot-toolkit -v
webex_bot_core v3.1.2
From a checkout:
make dev # .venv + editable install with dev extras
make test
Quick Start
- Create a
config.yml(see Configuration) - Create your command files in a
commands/directory - Run the bot:
bot-toolkit -c config.yml
Configuration
config.yml
# bot section
bot:
name: "Webex Bot Core"
token: ""
command_home: commands
callback_room: ""
# authentication and RBAC
auth:
domain:
- example.com
roles:
admin:
emails:
- admin@example.com
patterns:
- "*-admin@example.com"
default_role: user
# command switch — supports bool (legacy) or dict with enabled + roles
commands:
single_command:
enabled: true
roles: [user]
card_command:
enabled: true
roles: [operator, admin]
# scheduler
scheduler:
enabled: true
db_path: "data/scheduler.db"
seed_jobs:
- type: command
command: single_command
schedule: "0 9 * * 1"
target_user_email:
- user@example.com
# logging level: DEBUG, INFO, WARNING, ERROR
logging:
level: INFO
# help card
help:
card_image_url: "https://example.com/image.jpg"
subtitle: "Bot Help Message"
Authentication and RBAC
The auth module provides domain-based allowlisting and role-based access control.
Domain allowlist — only users from listed domains can interact with the bot:
auth:
domain:
- example.com
Roles — define named roles with explicit email members and wildcard patterns:
auth:
roles:
admin:
emails:
- admin@example.com
patterns:
- "*-admin@example.com"
operator:
emails: []
patterns:
- "*-ops@example.com"
default_role: user # all domain-approved users get this role
Role resolution: every authenticated user receives default_role automatically. Additional roles are granted if the user's email matches any entry in emails or patterns (glob-style matching).
Commands
Commands can be enabled/disabled and optionally bound to RBAC roles:
# Extended format (recommended)
commands:
single_command:
enabled: true
roles: [user] # accessible by all authenticated users
card_command:
enabled: true
roles: [admin] # restricted to admin role
# Legacy format (still supported)
commands:
single_command: true # equivalent to enabled: true, roles: [default_role]
Scheduler
The scheduler replaces the old plugins.cronjob with a SQLite-backed system supporting four job types, interactive Adaptive Card management, and per-user data.
scheduler:
enabled: true
db_path: "data/scheduler.db"
When enabled, two built-in commands are registered:
scheduler admin— admin panel (requiresadminrole)scheduler— user panel (all authenticated users)
Developing Commands
Project Structure
my-bot/
├── cards/
│ └── example.json
├── commands/
│ ├── single_command.py
│ └── card_command.py
└── config.yml
cards/— Adaptive Card JSON filescommands/— command modules (configurable viabot.command_home)config.yml— bot configuration
Single Command
from webex_bot_core.commands.base import BaseCommandInterface
from webex_bot_core.utils.formatting import quote_info
class BaseCommand(BaseCommandInterface):
NAME = "single_command"
HELP_MESSAGE = "Single Command"
def __init__(self, configs, raise_exception=False, notification=None):
super().__init__(configs, raise_exception=raise_exception, notification=notification)
def execute(self, message, attachment_actions, activity):
self._log.info("Start to execute")
self._notification.send_notification(f"message: {message}")
self._notification.callback("Example callback to admin space")
return "This is an example of how to develop a module."
def pre(self, message, attachment_actions, activity, **kwargs):
super().pre(message, attachment_actions, activity, **kwargs)
return quote_info("This is an example of pre-executing.")
Key points:
- Must inherit from
BaseCommandInterfaceand be namedBaseCommand NAME— the command keyword users type to trigger itHELP_MESSAGE— shown in the help cardpre()— called beforeexecute(), must callsuper().pre(...)firstexecute()— main logic, return a string,Response, or listself._notification— send messages, callbacks, and threaded repliesself._configs— access to allconfig.ymlvalues
Card Command
import json
from webexpythonsdk.models.cards import (
Colors, TextBlock, FontWeight, FontSize, Column, AdaptiveCard,
ColumnSet, Choice, ChoiceSet,
)
from webexpythonsdk.models.cards.actions import Submit
from webex_bot_core.commands.base import BaseCommandInterface
from webex_bot_core.models.response import Response, response_from_adaptive_card
class BaseCommand(BaseCommandInterface):
NAME = "card_command"
HELP_MESSAGE = "Card Command"
def __init__(self, configs):
super().__init__(configs)
self.chained_commands.append(CardCallbackEx1(configs))
def execute(self, message, attachment_actions, activity):
response = Response()
response.text = self.NAME
with open("cards/example.json", "r", encoding="utf-8") as f:
example_card = json.load(f)
actions = [
{
"type": "Action.Submit",
"title": "action 1",
"data": {
"callback_keyword": "callback_1",
"thread_parent_id": self._notification.get_parent_id(),
},
},
]
example_card["body"].append({"type": "ActionSet", "actions": actions})
response.add_attachment({
"contentType": "application/vnd.microsoft.card.adaptive",
"content": example_card,
})
return response
def pre(self, message, attachment_actions, activity, **kwargs):
super().pre(message, attachment_actions, activity, **kwargs)
return f"{self.NAME} pre execute"
class CardCallbackEx1(BaseCommandInterface):
CALLBACK_KEYWORD = "callback_1"
NAME = "card_command callback1"
def __init__(self, configs):
super().__init__(configs, delete_previous_message=False)
def execute(self, message, attachment_actions, activity):
return "callback1 execute success"
Key points:
- Use
chained_commandsto register card callback handlers - Set
CALLBACK_KEYWORDon callback classes (matched when card buttons are clicked) - Always pass
thread_parent_idin card action data to maintain threading - Use
response_from_adaptive_card()for SDK card objects, or build raw JSON withResponse.add_attachment()
Scheduler System
Overview
The scheduler provides persistent, SQLite-backed job scheduling with interactive Adaptive Card management for both admins and users.
Architecture:
- JobStore (
scheduler/store.py) — SQLite persistence for jobs and subscriptions - SchedulerEngine (
scheduler/engine.py) — APScheduler wrapper with live job management - Job executors (
scheduler/jobs/) — type-specific execution logic - Admin/User commands (
commands/scheduler/) — card-based CRUD interfaces
Job Types
| Type | Description | Targets |
|---|---|---|
command |
Execute a bot command on schedule | Static: emails + rooms |
script |
Run a bash script on the host | Static: emails + rooms |
remind |
Send a message (markdown, table, or card) | Static: emails + rooms |
subscribe |
Execute a command, deliver to subscribers | Dynamic: from subscriptions table |
Admin Interface
Trigger: type scheduler admin or click from help card.
The admin panel allows:
- Creating any job type (command, script, remind, subscribe service)
- Viewing all jobs across all users with status
- Enabling / disabling / deleting jobs
- Viewing subscribers for subscribe-type services
Script jobs can only be created by users with the admin role.
User Interface
Trigger: type scheduler or click from help card.
The user panel allows:
- Viewing and managing own jobs (create, enable/disable, delete)
- Creating command, script, or remind jobs
- Browsing available subscription services
- Subscribing / unsubscribing from services
- Viewing active subscriptions
Release Notes
- v3.1.2
- Shared helpers live in one module,
webex_bot_core.utils.common_libs:SuperDict(dotted-key config access),yaml_file_concurrent_operation,check_file_validation,load_module,ArgsUtil,LogInitializer, and theCommonLibsErrorhierarchy thatBotExceptionandBotConfigExceptionderive from. Standard library and PyYAML only. - Removed
load_yamlanddotted_getfromwebex_bot_core.utils.common(added in 3.1.1); useyaml_file_concurrent_operationandSuperDict.
- Shared helpers live in one module,
- v3.1.1 — first public release on PyPI
- No dependencies outside PyPI.
- Dropped the unused
coloredlogsdependency. - Packaging moved to
pyproject.toml;bot-toolkitis the only installed entry point. - Mercury activity redeliveries are de-duplicated for both messages and card
actions (
bot.activity_dedupe_seconds, default 120). - Optional
.envfile support for local environment variables.
- v3.0.2
- Security fix — RBAC propagation to chained sub-commands.
The loader only assigned the configured
roleslist to the top-level command instance, so card-callback handlers appended toself.chained_commands(the typical place for "Submit" handlers behind Adaptive Cards) silently bypassed the role gate. When an admin posted an admin-only card in a multi-user space, any room member could click the card's Submit action and the dispatcher would skip the RBAC check because the sub-command'srequired_roleswas stillNone.BotCorenow recursively propagatesrequired_rolesto every chained sub-command (including nested chains) while preserving stricter overrides set explicitly inside a sub-command's__init__. No bot code changes are required — sub-commands automatically inherit the parent's role gate.
- Security fix — RBAC propagation to chained sub-commands.
The loader only assigned the configured
- v3.0.1
- Fix
AttributeError: 'InvalidStatus' object has no attribute 'status'raised on Mercury WebSocket handshake 404 (stale WDM device).websockets >= 12moved the status ontoexc.response.status_code; the 404 recovery path now probes both the new and the legacy attribute layouts, so bots onwebsockets9–16 all recover the same way and transparently re-register the device instead of crashing.
- Fix
- v3.0.0 — webex-bot-v2 rewrite
- Removed upstream
webex_botdependency; standalone WebSocket transport - Migrated to
webexpythonsdk(Python >= 3.10) - Added RBAC auth module with role definitions, email patterns, and per-command role binding
- Replaced cronjob plugin with full scheduler system (SQLite, 4 job types, interactive card UI)
- Redesigned help card with rich Adaptive Card layout
- Configurable logging level via
config.yml - Consistent message threading for card actions and text commands
- Removed upstream
- v2.0.0
- Renamed callback to utils
- Moved utils.py to utils/common.py
- Added plugins/ library
- Added cronjob plugin
- v1.2.0
- Added person_email target support in notification
- Added traceback
Reference
Support
- Issues and pull requests: https://github.com/liozzazhang/webex-bot-core/issues
License
This is an independent community project, not an official Webex product.
Metadata
Release files for webex-bot-core 3.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| webex_bot_core-3.1.2.tar.gz | 74.0 kB | Without provenance | Details for webex_bot_core-3.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| webex_bot_core-3.1.2-py3-none-any.whl | Python 3 | none | any | Details for webex_bot_core-3.1.2-py3-none-any.whl |
Total release size: 150.3 kB
Release files / webex_bot_core-3.1.2.tar.gz
| Download URL | webex_bot_core-3.1.2.tar.gz |
|---|---|
| Size | 74.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c5f3540f7362a6d6aaf7e8e109fb6239c1be7cfd2af17606924f4eeade0c21d
|
|
BLAKE2b-256 checksum How to use checksums |
1c7469366f7bd6d2d4b1e562a82bebbfd20ac4d6d0d4f9530b8e12074a1c6156
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Release files / webex_bot_core-3.1.2-py3-none-any.whl
| Download URL | webex_bot_core-3.1.2-py3-none-any.whl |
|---|---|
| Size | 76.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6bdd2c25346d41bdd0bf8a232769fb52c089c5496375b3a73191827444d27b4
|
|
BLAKE2b-256 checksum How to use checksums |
167b859656d06e7e8ac767156b5f553be36510076237a538c50255838be6d049
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Security for webex-bot-core 3.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.