Extended messaging: broadcasts, multiple numbers, Messenger and Instagram, files and AI assistant
Everything runs on the client’s own accounts and keys; nothing on the public pages (only signed REST routes and the queue).
Multiple WhatsApp numbers (Builder_OS_CRM_WA_Lines, class-builder-os-crm-wa-lines.php). The main number stays in the “WhatsApp (Meta Cloud API)” card (builder_os_crm_channels['whatsapp']); additional ones go in the builder_os_crm_wa_lines option (id = its phone_number_id, name, waba_id if it belongs to another account, optional own token encrypted like the others, activated). They share the Meta app: secret, webhook and verification token. The messaging tables move to version 3 (builder_os_crm_msg_db_version): line column in conversations and messages, unique key contact_channel_line (contact_id, channel, line) (the old contact_channel is dropped) and broadcast_id in messages. The migration (its own version, builder_os_crm_wa_lines_version) moves the existing WhatsApp conversations and messages to the main number without touching its settings; an old conversation with no number counts as belonging to the main one. The webhook routes by value.metadata.phone_number_id and ignores numbers that don’t belong to the site. The 24 h window is per number; reply() goes out through the conversation’s number; broadcasts and the “Send a WhatsApp message” step of automations choose a number (line field). In context (enter() / leave() / with_line()), the WhatsApp channel uses that number’s ID, account (templates cached per WABA: builder_os_crm_wa_templates_<waba>) and token. Internal API: Builder_OS_CRM_Conversations::ensure|by_contact|window_open|window_left( …, $line = null ), default_line(), filter builder_os_crm_default_line, action builder_os_crm_conversation_assigned. REST (bos_crm_settings to write, bos_crm_view to read): GET|POST crm/whatsapp/lines, DELETE crm/whatsapp/lines/{id}, POST crm/whatsapp/lines/{id}/test. They never return tokens (only has_token).
SMS and WhatsApp broadcasts (Builder_OS_CRM_Broadcasts and its screen, which now lives in CRM → Campaigns (each broadcast is a row in the list with its channel and there is a channel filter; the Broadcasts URL redirects there); tables {prefix}bos_crm_broadcasts and {prefix}bos_crm_bc_recipients, version builder_os_crm_bc_db_version). Audience: segments (static ones too, the “lists”) and tags, with exclusions. SMS: text with {{nombre}}, {{apellidos}}… (“Reply STOP…” is added). WhatsApp: approved template only (variables with {{nombre}}, header, buttons) and an outgoing number. Count (will receive it, no permission, no phone, excluded), blocks, preview with a real contact, test to one contact (same rules) and “Send now” / “Schedule” (only a person with bos_crm_send). Built through the queue (crm.bc_build, chunks of 200 by cursor) with one row per recipient (queued with its message or skipped with the reason): repeating a chunk never writes twice. Sending uses Builder_OS_CRM_Messaging::send_bulk() (which accepts a callable per contact and chunk): per-channel opt-in (subscribed), STOP, allowed hours (defers), revalidation before each send and batches the size of the provider’s quota per window (at most 25), so the pace really slows down. Report: recipients, queued, sent, delivered, read, failed, not sent with reason and replies (people who wrote in that conversation within 7 days). Cancel leaves what is pending as skipped / cancelled. REST: crm/broadcasts (GET, POST), crm/broadcasts/{id} (GET, POST, DELETE), …/{id}/preview, …/{id}/test|schedule|unschedule|cancel (bos_crm_send). MCP (group “CRM: SMS and WhatsApp”): crm_list_broadcasts, crm_get_broadcast_report (read) and crm_create_broadcast (draft only; there is no tool to launch or schedule).
Messenger and Instagram Direct (class-builder-os-crm-channel-meta-social.php: channels messenger and instagram that implement Builder_OS_CRM_Channel, plus Builder_OS_CRM_Meta_Social). Settings in the “Messenger and Instagram Direct” card: Page ID or Instagram professional account ID and page token (encrypted; constants BUILDEROS_MESSENGER_PAGE_TOKEN, BUILDEROS_INSTAGRAM_PAGE_TOKEN). The app secret and the verification token are the WhatsApp ones (same Meta app). Webhooks GET|POST /wp-json/builder-os/v1/hooks/meta/messenger|instagram (las anteriores, crm/hook/messenger|instagram, valen durante 4.18.x): hub.* verification and X-Hub-Signature-256 required (no secret or a bad signature, 403); echoes, other pages and repeats are ignored; messages, deliveries, reads and postbacks. People are identified by PSID / IGSID in {prefix}bos_crm_identities (version builder_os_crm_ident_db_version); the first message creates the contact (no phone or marketing consent). Sent through POST /me/messages with the token in the header. 24 h window: inside it, RESPONSE; outside it, only HUMAN_AGENT for a team member up to 7 days (never the AI or a broadcast) and, on Messenger only and for transactional notices requested by code, CONFIRMED_EVENT_UPDATE, POST_PURCHASE_UPDATE or ACCOUNT_UPDATE. A conversation cannot be started. STOP / START mark the opt-out on the identity. Meta requirement: without Advanced Access to pages_messaging and instagram_manage_messages (App Review and business verification) the app only talks to people who have a role in it; “Test connection” reminds you because it cannot be checked from the API.
Files (image, audio, document, video). Builder_OS_CRM_Messaging::send( $contacto, $canal, array( 'media' => array( 'id' => <adjunto de POST crm/attachments>, 'type' => 'image'|'audio'|'document'|'video', 'caption' => '…' ) ), $opts ) and Builder_OS_CRM_Messaging::reply( $conversación, $pie, array(), array( 'media' => array( 'id', 'type', 'caption' ) ) ) (the attachments => array( id ) form is still valid; REST POST crm/inbox/{id}/reply accepts media). The type is checked against the actual content; one file per message; same rules as text (permission, STOP, window or template). WhatsApp: uploaded to /{phone_number_id}/media and sent by id (OGG audio in Opus only; MP3, M4A/AAC and AMR too). Twilio: MMS with a signed MediaUrl only to +1 (US and Canada), with MMS enabled, MMS types and up to 5 MB; in all other cases, SMS with a signed link that expires after 7 days (filter builder_os_crm_attachment_link_ttl). Messenger and Instagram: attachment by a 30-minute signed URL (the caption goes first as text; Instagram without PDF). Email (IMAP replies): regular attachment with SMTP and Brevo, signed link with SES; up to 10 MB. Signed URLs respond with Cache-Control: no-store and X-Robots-Tag: noindex; the regular URL requires a session. Incoming Messenger and Instagram files: downloaded through the queue only from Meta’s CDN over https (filter builder_os_crm_meta_media_hosts) to uploads/bos-crm-private/; they are deleted with the contact (GDPR), like their identities, AI turns and broadcast rows.
Composer: emojis and voice notes. admin/js/builder-os-crm-inbox-composer.js (loads before builder-os-crm-inbox.js; exposes window.BOSCRMI_COMPOSER):
emojiButton(ctx): picker with categories, search (words in Spanish and English) and recents, which inserts at the cursor. The list ships inside the file, no CDN.micButton(ctx): voice note withMediaRecorder: record (with a counter), cancel, stop, listen and send. The format is chosen withMediaRecorder.isTypeSupportedamong those the channel accepts, in this order: OGG/Opus, WebM/Opus, MP4 (AAC). The server validates the file again.restore(ctx)recovers the recording if the composer repaints;cancel()stops it when the conversation changes.- One file per message:
builder-os-crm-inbox-media.jstakes the first one when dragging, choosing or pasting (files[0]). Each channel sends it according to its own rules (see “Files”). - If the browser does not grant microphone access, the button does not appear or shows a notice: recording needs HTTPS and the user’s permission.
AI Assistant (class-builder-os-crm-ai-agent.php, -ai-guard.php, -ai-provider.php, -ai-admin.php; tables {prefix}bos_crm_ai_state and {prefix}bos_crm_ai_turns, version builder_os_crm_ai_db_version; settings in builder_os_crm_ai, “AI Assistant” card). Provider: the client’s key (encrypted or BUILDEROS_AI_API_KEY; it never goes back to the browser); Anthropic by default (POST /v1/messages, anthropic-version: 2026-10-21, changeable model claude-haiku-5-5, output_config with low effort and json_schema output) or an OpenAI-compatible https endpoint. Prices per million tokens are configurable (default US$0.10 / 0.50). It only runs through the queue (crm.ai_turn, provider ai, one per conversation and a few seconds after the message). Settings: channels or numbers, hours (always, only inside or only outside), personality and tone, knowledge base (text, chosen pages and products), goals, appointment types, allowed tags and fields, handoff rules, caps (per conversation, per day, daily tokens and spend) and AI notice ({negocio}). The card no longer has an on switch: it says “It is turned on, paused and limited in CRM › Autopilot. Personality, knowledge and channels go here.” with the link “Open Autopilot” (Limits view, only if the Autopilot is visible). It only responds with the Autopilot active (Builder_OS_CRM_Autopilot::trigger_on('message'): AI key, on, not paused and circuit breaker closed); the old 4.13 enabled setting opens no path (fails closed) and there is no legacy automatic reply anymore.
- Before the model (no spend): hours, VIP tag, keywords (accent-insensitive), “I want to talk to a person”, caps, spend cap, unresolved turns and the channel allowing a reply (
Messaging::checkwith the same rules as a person). It does not answer STOP and START. - Prompt-injection security: the prompt carries only the fixed rules, the settings, the knowledge, the first name and the last 12 messages of that conversation, with the person’s content between
<mensaje_cliente>as data; never data from other contacts or the key. The model only returns JSON (reply,actions,confidence,sentiment,resolved) and has no tools. Whitelist validated on the server:handoff,add_tag(only the allowed ones),set_field(only the chosen fields),book_appointment(allowed type and a truly free slot,Appointments::book) andcreate_task; at most 3 per turn; the rest is rejected and logged. The text is cleaned: no HTML, no links that aren’t the site’s, no emails or phones that aren’t in the knowledge or the contact’s own. It goes out throughMessaging::send(ai => true, actor “AI Assistant”), with the AI notice in its first message of the conversation. - Handoff (
handoff, reason in the state): asks for a person, keyword, VIP, low confidence, anger, thehandoffaction, unresolved turns, caps, provider error or invalid output, or an appointment that could not be booked. It sends the handoff message, creates a task (optional) and logs it in the timeline. In Pilot, a person who replies from the Inbox or assigns the conversation to themselves pauses the AI there (reasonshuman_replyandassigned); in Copilot their reply replaces the pending proposal and assigning pauses nothing. It resumes withPOST crm/ai/conversations/{id}/resume. - Inbox:
composer.ai(stateresponding | paused | handoff | inactive | off,label,reason_label,detail,can_toggle) andai: trueon the AI’s messages; its own pill that says “AI assistant active”, “AI assistant paused” (with “Passed to a person · reason” if it was a handoff) or “AI assistant inactive” (a channel or number that doesn’t reply), with the Pause / Resume button (readsconvfrom the URL). REST:GET|POST crm/ai/settings,POST crm/ai/test,GET crm/ai/conversations/{id},POST …/pause|resume. Actionbuilder_os_crm_ai_handoff; filtersbuilder_os_crm_ai_rateandbuilder_os_crm_ai_anthropic_url.
Firewall and uninstall. hook/(?:messenger|instagram) is declared in builder_os_firewall_signed_routes. Uninstalling deletes the new tables (Builder_OS_CRM_Schema::msg_ext_tables()) and the builder_os_crm_* options.
For the AI prompt (chapter 25). SMS or WhatsApp broadcasts are only prepared as a draft with crm_create_broadcast (WhatsApp, only with a template from crm_list_whatsapp_templates); a person launches them in CRM → Campaigns (broadcasts are rows in the list, with their channel). With multiple numbers, specify line and don’t mix numbers in one conversation. On Messenger and Instagram you cannot write to someone who hasn’t written first, or outside the 24 h (except a team member); don’t promise the client it will work without Meta’s Advanced Access. Don’t activate the AI assistant (it is turned on in CRM → Autopilot) without a knowledge base, spend caps and AI notice reviewed with the client, and don’t give it sensitive tags or fields.
Checklist.
- Multiple numbers: each with “Test connection” green; each account’s
messagesfield subscribed to the same app; a message to each number lands in its own conversation and the reply goes out through it. - Test broadcast (CRM → Campaigns, WhatsApp or SMS channel) to a small segment: correct count, preview, test to one contact and the report with delivered, read and replies; those without permission don’t receive it.
- Messenger / Instagram: Advanced Access approved (or tests only with app roles), webhooks subscribed, “Test connection” and a message back and forth.
- Files: an image over WhatsApp within 24 h, an SMS outside the US with its link (expires) and a PDF by email; a file received on Messenger shows in the thread.
- AI assistant: key tested, Autopilot on (without it, it doesn’t reply), knowledge base with no private data, AI notice, token and spend caps, handoff rules; a test conversation with “I want to talk to a person” moves to the Inbox; in Pilot, replying manually pauses it (in Copilot it replaces the proposal).