1. Template Techniques
  2. Notification Platform Switching

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:

        "_com_platforms": {
  "last_incoming_platform": "whatsapp",
  "last_from_raw": "27820000000",
  "last_from": {
    "webchat": "<webchat sessionuuid>",
    "whatsapp": "27820000000"
  }
}

      
  • 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 _create context's _update_from_<platform> actions create the default stub 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 on default relays the message to the main chat with a gpt_chat_task.
  • _update_from_chat_assistant_task has one notification per platform. Each is conditioned on stub.data._com_platforms.last_incoming_platform = "<platform>", sends ~~stubpost.message, and sets stubsession.set_new_with_timeout_hours so 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_platform notification with com_platforms_data: "~~stub.data._com_platforms" replaces the per-platform ones. WhatsApp needs its own meta_whatsapp notification.
  • To switch on request: the webchat switching client configuration lets the user pick a platform, which arrives as stubpost.data._incoming_webchat_data.webchat_client_configuration.platform_switch (platform, value). A gpt_chat_task injects this as a system message, and an AI-enabled action then sends the first message on the new platform. The send goes to value (or last_from.<platform> when known), sets a stubsession there, and saves last_incoming_platform to 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 _create stub and starts a new conversation.
  • Don't let the LLM pick the platform from conversation text alone. Route on _com_platforms and switch only through an explicit action.