You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`ServiceBridge` is the fastest way to expose any service as a chat-controllable interface. Instead of wiring up `CommandMiddleware` by hand, you call `expose()` and get automatic `/help`, argument parsing, error handling, and sync-function support for free.
831
+
832
+
```python
833
+
import asyncio
834
+
from unified_channel import ChannelManager, TelegramAdapter, ServiceBridge
This gives you `/help`, `/deploy`, `/disk`, `/status`, `/logs`, and `/whoami` — all with automatic error handling. If a command throws, the user gets a friendly error message instead of silence.
867
+
868
+
### Flag parsing
869
+
870
+
Arguments like `--force` and `--count 3` are automatically parsed:
Load channels and middleware from a config file instead of writing Python:
888
+
889
+
```yaml
890
+
# unified-channel.yaml
891
+
channels:
892
+
telegram:
893
+
token: "${UC_TELEGRAM_TOKEN}"
894
+
discord:
895
+
token: "${UC_DISCORD_TOKEN}"
896
+
slack:
897
+
bot_token: "${UC_SLACK_BOT_TOKEN}"
898
+
app_token: "${UC_SLACK_APP_TOKEN}"
899
+
900
+
middleware:
901
+
access:
902
+
allowed_users: ["admin_id_1", "admin_id_2"]
903
+
904
+
settings:
905
+
command_prefix: "/"
906
+
```
907
+
908
+
```python
909
+
from unified_channel import load_config, ServiceBridge
910
+
911
+
manager = load_config("unified-channel.yaml")
912
+
bridge = ServiceBridge(manager)
913
+
bridge.expose("status", lambda args: "OK")
914
+
asyncio.run(bridge.run())
915
+
```
916
+
917
+
Environment variables are interpolated with `${VAR}` syntax. Adapters are auto-detected by name. Returns a fully configured `ChannelManager` ready to use.
918
+
919
+
---
920
+
826
921
## Real-World Example
827
922
828
923
A complete remote management bot for a job queue system:
@@ -933,6 +1028,22 @@ if __name__ == "__main__":
933
1028
|-----------|-------------|
934
1029
|`allowed_user_ids`|`set[str]` of allowed sender IDs. `None` = allow all |
935
1030
1031
+
### ServiceBridge
1032
+
1033
+
| Method | Description |
1034
+
|--------|-------------|
1035
+
|`ServiceBridge(manager, prefix="/")`| Create a bridge wrapping a `ChannelManager`|
1036
+
|`expose(name, handler, description, params)`| Expose a function as a chat command |
0 commit comments