Template Techniques
Notification Platform Switching
Explains how one conversation stub can reply on the platform the user last wrote from and move between platforms, using the _com_platforms data structure.
One conversation stub can talk to a user on more than one platform (webchat, WhatsApp, Telegram, email, Slack). Replies should go out on the platform the user last wrote from, and the conversation can move from one platform to another without losing the stub, its data or the LLM chat.
The Stubber Platform tracks this in _com_platforms. Every incoming _update_from_<platform> feedback action carries stubpost.data._com_platforms, which merges into stub.data._com_platforms:
last_incoming_platform: the platform of the most recent incoming message. Route replies on this.last_from_raw: the sender address on that platform (mobile number, webchat sessionuuid, Telegram chat id, email address).last_from.<platform>: the last known address per platform. It builds up as the user writes on more platforms, so it tells you where else you can reach them.- Telegram can also add
telegram_chat_type.
Always route on _com_platforms. It is the only way to tell which platform to reply on.
Detailed Example Structure
- The
_createcontext's_update_from_<platform>actions create thedefaultstub and pass"_com_platforms": "~~stubpost.data._com_platforms"in its data, so the stub knows its platform from the first message. - Each
_update_from_<platform>action ondefaultrelays the message to themainchat with agpt_chat_task. _update_from_chat_assistant_taskhas one notification per platform. Each is conditioned onstub.data._com_platforms.last_incoming_platform = "<platform>", sends~~stubpost.message, and setsstubsession.set_new_with_timeout_hoursso the user's next message comes back to this stub.- For platforms it supports (Telegram, Slack, Teams, Webchat per the library item), a single
auto_platformnotification withcom_platforms_data: "~~stub.data._com_platforms"replaces the per-platform ones. WhatsApp needs its ownmeta_whatsappnotification. - To switch on request: the webchat
switchingclient configuration lets the user pick a platform, which arrives asstubpost.data._incoming_webchat_data.webchat_client_configuration.platform_switch(platform,value). Agpt_chat_taskinjects this as a system message, and an AI-enabled action then sends the first message on the new platform. The send goes tovalue(orlast_from.<platform>when known), sets a stubsession there, and saveslast_incoming_platformto the new platform so later replies follow. - To reach the user proactively on a platform other than the last one (e.g. a reminder on WhatsApp after a webchat chat), use
stub.data._com_platforms.last_from.<platform>as the recipient. Check that it exists first.
Things to watch
- Templates don't need to handle WhatsApp's 24-hour messaging window. Stubber handles it: outside the window it automatically sends a standard WhatsApp template message asking the user for permission to continue the session.
- Set the stubsession on every outgoing message, or the next incoming message lands on the
_createstub and starts a new conversation. - Don't let the LLM pick the platform from conversation text alone. Route on
_com_platformsand switch only through an explicit action.