Goal: plug OmegaClaw into a new communication surface (Slack, Discord, a REST endpoint, a terminal) by writing a channel adapter.
- A local clone.
- Familiarity with the existing adapters in
channels/irc.py,channels/telegram.py, andchannels/slack.py.
A channel adapter is a Python module that exposes:
start_<name>(...)— called once frominitChannelsinsrc/channels.metta. Opens any background threads/sockets needed.getLastMessage()— returns the most recent unread inbound message as a string, or an empty string if none.send_message(str)— posts a string outbound.
The MeTTa side in src/channels.metta dispatches on the commchannel configuration:
(= (receive)
(if (== (commchannel) irc)
(py-call (irc.getLastMessage))
(if (== (commchannel) telegram)
(py-call (telegram.getLastMessage))
(if (== (commchannel) slack)
(py-call (slack.getLastMessage))
(py-call (mattermost.getLastMessage))))))Your adapter adds another branch to that dispatch.
Create channels/myadapter.py exposing start_myadapter, getLastMessage, and send_message. Model the file on channels/irc.py:
_inbox = []
def start_myadapter(...):
# open a socket, spawn a listener thread, etc.
...
def getLastMessage():
if _inbox:
return _inbox.pop(0)
return ""
def send_message(msg):
# publish msg to your surface
...In src/channels.metta:
- Add a
(= (MY_*) (empty))entry for each runtime parameter your adapter needs. - Extend
initChannelswith a new branch that callsconfigureand then(py-call (myadapter.start_myadapter ...)). - Extend
(receive)and(send $msg)with corresponding branches.
Make sure the file can be found. The existing adapters are imported by virtue of being in channels/ and being called via py-call. If you need explicit imports, add them alongside the others.
Set commchannel to your new name — either by editing initChannels or through an argk override on startup.
- On startup, logs show your adapter's initialization line.
- Messages sent through your surface land in
getLastMessage()and trigger aHUMAN-LAST-MSGin the loop. (send ...)calls reach the surface.
- reference-channels.md — the full adapter reference.
- reference-internals-extension-points.md — other extension seams.