#!/usr/bin/env python3 import subprocess import logging from signalwire.relay.consumer import Consumer PROJECT = "16fbbcfd-1c94-4827-869c-0364f5f67488" TOKEN = "PTfb129c5160af67841e2da19d5e9d94bcf6312a81fa43f248" CONTEXT = "Texting for Fusion" FUSION_DOMAIN = "fusion.orbishosting.com" TARGET_EXT = "1001" logging.basicConfig(level="INFO") log = logging.getLogger("sms-inbound") class TextConsumer(Consumer): def setup(self): self.project = PROJECT self.token = TOKEN self.contexts = [CONTEXT] def ready(self): log.info(f"Connected to SignalWire Relay, listening on context: {self.contexts}") def on_incoming_message(self, message): from_num = message.from_number body = message.body or "" log.info(f"Inbound SMS from {from_num}: {body}") deliver_to_phone(from_num, body) def deliver_to_phone(from_num, body): safe_body = body.replace('"', "'").replace("\n", " ") chat_line = f"sip|{from_num}@{FUSION_DOMAIN}|internal/{TARGET_EXT}@{FUSION_DOMAIN}|{safe_body}" result = subprocess.run( ["fs_cli", "-x", f"chat {chat_line}"], capture_output=True, text=True ) log.info(f"fs_cli chat delivery result: {result.stdout.strip()} {result.stderr.strip()}") if __name__ == "__main__": consumer = TextConsumer() consumer.run()