{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-docs/functions/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["partial"]},"type":"markdown"},"seo":{"title":"Developer Documentation","siteUrl":"https://developers.sinch.com","llmstxt":{"title":"Sinch Developer Documentation","description":"LLMs.txt containing a map of all the documentation files for Sinch.","sections":[{"title":"SMS API","description":"The SMS API allows you to send and receive SMS messages with a few easy steps. You can also send bulk SMS messages to multiple customers using the Sinch SMS service.","includeFiles":["docs/sms/**/*.md","docs/sms/**/*.yaml"],"excludeFiles":["docs/sms/index.md"]},{"title":"Numbers API","description":"The Numbers API enables you to search for, view, and activate numbers. It's considered a precursor to other APIs in the Sinch product family. The numbers API can be used in tandem with any of our APIs that perform messaging or calling.","includeFiles":["docs/numbers/**/*.md","docs/numbers/**/*.yaml"],"excludeFiles":["docs/numbers/index.md"]},{"title":"Conversation API","description":"Send and receive messages globally on many popular channels with ease and confidence when using Sinch's Conversation API. Conversation API is the preferred API for sending mobile messages on SMS and other social channels with Sinch. It is a simple API with unified error messages, consistent request payloads, and common webhook payloads that are channel-agnostic.","includeFiles":["docs/conversation/**/*.md","docs/conversation/**/*.yaml"],"excludeFiles":["docs/conversation/index.md"]},{"title":"Voice API","description":"The Voice API works as a big telephony switch. The Voice API handles incoming phone calls (also known as incoming call “legs”), sets up outgoing phone calls (or outgoing call “legs”), and bridges the two. The incoming call leg may come in over a data connection (from a smartphone or web application using the Sinch SDKs) or through a local phone number (from the PSTN network). Similarly, the outgoing call leg can be over data (to another smartphone or web application using the Sinch SDKs) or the PSTN network.","includeFiles":["docs/voice/**/*.md","docs/voice/**/*.yaml"],"excludeFiles":["docs/voice/index.md"]},{"title":"Verification API","description":"The Verification API is a platform for phone number verification. It consists of the API and different software development kits (the Sinch SDKs) that you integrate with your smartphone or web application and cloud based back-end services. Together they enable SMS, Flashcall, Phone Call and Data verification in your application.","includeFiles":["docs/verification/**/*.md","docs/verification/**/*.yaml"],"excludeFiles":["docs/verification/index.md"]},{"title":"Provisioning API","description":"Provisioning API allows you to programmatically set up your senders, accounts and templates on your favorite messaging platforms on the Conversation API. For now, you can create your first WhatsApp channel through Meta's Embedded sign up, you can configure your first SMS App and configure your webhooks. As development continues, we will be adding the most commonly used channels.","includeFiles":["docs/provisioning-api/**/*.md","docs/provisioning-api/**/*.json"],"excludeFiles":["docs/provisioning-api/index.md"]},{"title":"Elastic SIP Trunking API","description":"With Elastic SIP Trunking you can create and manage your SIP trunks and phone numbers programmatically.","includeFiles":["docs/est/**/*.md","docs/est/**/*.yaml"],"excludeFiles":["docs/est/index.md"]},{"title":"Fax API","description":"Send and receive HIPAA compliant faxes on our modern fax platform using our developer-friendly API.","includeFiles":["docs/fax/**/*.md","docs/fax/**/*.yaml"],"excludeFiles":["docs/fax/index.md"]},{"title":"In-app Voice and Video SDK","description":"The In-app Voice and Video SDK enables you to add voice and video calling capabilities directly into your mobile or web application using the Sinch SDKs.","includeFiles":["docs/in-app-calling/**/*.md"],"excludeFiles":["docs/in-app-calling/index.md"]}],"hide":false,"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"build-an-sms-responder","__idx":0},"children":["Build an SMS Responder"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Receive inbound SMS messages and send replies using the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/conversation/"},"children":["Sinch Conversation API"]},". The same code works for WhatsApp, Messenger, and any other channel your Conversation app supports."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"prerequisites","__idx":1},"children":["Prerequisites"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Declare secrets in ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":[".env"]}," with empty values and store them with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sinch secrets add"]},":"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"sinch secrets add CONVERSATION_APP_ID your-app-id\nsinch secrets add PROJECT_ID your-project-id\nsinch secrets add PROJECT_ID_API_KEY your-key-id\nsinch secrets add PROJECT_ID_API_SECRET your-key-secret\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"basic-responder","__idx":2},"children":["Basic responder"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"Node.js","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"import type { FunctionContext } from '@sinch/functions-runtime';\nimport {\n  ConversationController,\n  getText,\n  getChannel,\n  getContactId,\n} from '@sinch/functions-runtime';\nimport type { MessageInboundEvent } from '@sinch/functions-runtime';\n\nclass SmsHandler extends ConversationController {\n  async handleMessageInbound(event: MessageInboundEvent): Promise<void> {\n    const text = getText(event);\n    if (!text) return;\n\n    const channel = getChannel(event);\n    const contactId = getContactId(event);\n    console.log(`Inbound from ${channel}: \"${text}\" (contact: ${contactId})`);\n\n    await this.conversation!.messages.send({\n      sendMessageRequestBody: this.reply(event, `You said: ${text}`),\n    });\n  }\n}\n\nexport async function setup(context: FunctionContext) {\n  const handler = new SmsHandler(context.conversation, {\n    CONVERSATION_APP_ID: context.env.CONVERSATION_APP_ID,\n    FROM_NUMBER: context.env.FROM_NUMBER,\n  });\n  return handler.getWebhookHandler();\n}\n","lang":"typescript"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"C#","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"using Microsoft.AspNetCore.Mvc;\nusing Sinch.Conversation.Hooks;\nusing SinchFunctions.Utils;\n\nnamespace SinchFunctions\n{\n    public class FunctionController : SinchConversationController\n    {\n        public FunctionController(\n            FunctionContext context,\n            IConfiguration configuration,\n            ILogger<FunctionController> logger)\n            : base(context, configuration, logger) { }\n\n        public override async Task<IActionResult> MessageInbound(MessageInboundEvent inbound)\n        {\n            var text = inbound.GetText();\n            if (string.IsNullOrEmpty(text)) return Ok();\n\n            var channel = inbound.GetChannel();\n            Logger.LogInformation(\"Inbound from {Channel}: {Text}\", channel, text);\n\n            await Context.Conversation!.Messages.Send(Reply(inbound, $\"You said: {text}\"));\n            return Ok();\n        }\n    }\n}\n","lang":"csharp"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"helper-functions","__idx":3},"children":["Helper functions"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"Node.js","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"import {\n  getText,\n  getChannel,\n  getContactId,\n  getConversationId,\n  getIdentity,\n  getMedia,\n  getPostbackData,\n  isTextMessage,\n  isMediaMessage,\n  isPostback,\n} from '@sinch/functions-runtime';\n\nconst text = getText(event); // 'Hello'\nconst channel = getChannel(event); // 'SMS', 'WHATSAPP', 'MESSENGER'\nconst contactId = getContactId(event); // Sinch contact ID\nconst identity = getIdentity(event); // Sender's phone/PSID/etc.\n","lang":"typescript"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"C#","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"using SinchFunctions.Utils;\n\nvar text = inbound.GetText();\nvar channel = inbound.GetChannel();   // \"SMS\", \"WHATSAPP\", \"MESSENGER\"\nvar contactId = inbound.GetContactId();\nvar identity = inbound.GetIdentity(); // Sender phone/PSID\n","lang":"csharp"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"sending-replies","__idx":4},"children":["Sending replies"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"simple-text-reply","__idx":5},"children":["Simple text reply"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"Node.js","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"await this.conversation!.messages.send({\n  sendMessageRequestBody: this.reply(event, 'Thanks for your message!'),\n});\n","lang":"typescript"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"C#","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"await Context.Conversation!.Messages.Send(Reply(inbound, \"Thanks for your message!\"));\n","lang":"csharp"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"send-to-a-specific-contact-by-id","__idx":6},"children":["Send to a specific contact by ID"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"Node.js","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"await this.conversation!.messages.send({\n  sendMessageRequestBody: {\n    app_id: this.config.CONVERSATION_APP_ID,\n    recipient: { contact_id: contactId },\n    message: { text_message: { text: 'A proactive message' } },\n  },\n});\n","lang":"typescript"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"C#","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"await Context.Conversation!.Messages.Send(new SendMessageRequest\n{\n    AppId = Configuration[\"CONVERSATION_APP_ID\"],\n    Recipient = new Recipient { ContactId = contactId },\n    Message = new AppMessage\n    {\n        TextMessage = new TextMessage { Text = \"A proactive message\" }\n    }\n});\n","lang":"csharp"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"send-via-explicit-channel-sms","__idx":7},"children":["Send via explicit channel (SMS)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For SMS you must set ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["SMS_SENDER"]}," with your Sinch number. ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["this.reply()"]}," / ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Reply()"]}," does this automatically using ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["FROM_NUMBER"]},". For manual sends:"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"Node.js","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"await this.conversation!.messages.send({\n  sendMessageRequestBody: {\n    app_id: this.config.CONVERSATION_APP_ID,\n    recipient: { contact_id: contactId },\n    message: { text_message: { text: 'Reply via SMS' } },\n    channel_priority_order: ['SMS'],\n    channel_properties: {\n      SMS_SENDER: this.config.FROM_NUMBER,\n    },\n  },\n});\n","lang":"typescript"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"C#","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"await Context.Conversation!.Messages.Send(new SendMessageRequest\n{\n    AppId = Configuration[\"CONVERSATION_APP_ID\"],\n    Recipient = new Recipient { ContactId = contactId },\n    Message = new AppMessage { TextMessage = new TextMessage { Text = \"Reply via SMS\" } },\n    ChannelPriorityOrder = new List<ConversationChannel> { ConversationChannel.Sms },\n    ChannelProperties = new Dictionary<string, string>\n    {\n        [\"SMS_SENDER\"] = Configuration[\"FROM_NUMBER\"] ?? \"\"\n    }\n});\n","lang":"csharp"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"keyword-based-routing","__idx":8},"children":["Keyword-based routing"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"Node.js","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"async handleMessageInbound(event: MessageInboundEvent): Promise<void> {\n  const text = getText(event)?.trim().toUpperCase();\n  if (!text) return;\n\n  let reply: string;\n  if (text === 'HELP') {\n    reply = 'Text HOURS for our hours, or STOP to unsubscribe.';\n  } else if (text === 'HOURS') {\n    reply = 'We are open Monday through Friday, 9 AM to 5 PM EST.';\n  } else if (text === 'STOP') {\n    reply = 'You have been unsubscribed. Text START to re-subscribe.';\n  } else {\n    reply = 'Thanks for reaching out. Text HELP for available commands.';\n  }\n\n  await this.conversation!.messages.send({\n    sendMessageRequestBody: this.reply(event, reply),\n  });\n}\n","lang":"typescript"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"C#","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"public override async Task<IActionResult> MessageInbound(MessageInboundEvent inbound)\n{\n    var text = inbound.GetText()?.Trim().ToUpperInvariant();\n    if (string.IsNullOrEmpty(text)) return Ok();\n\n    var reply = text switch\n    {\n        \"HELP\"  => \"Text HOURS for our hours, or STOP to unsubscribe.\",\n        \"HOURS\" => \"We are open Monday through Friday, 9 AM to 5 PM EST.\",\n        \"STOP\"  => \"You have been unsubscribed. Text START to re-subscribe.\",\n        _       => \"Thanks for reaching out. Text HELP for available commands.\"\n    };\n\n    await Context.Conversation!.Messages.Send(Reply(inbound, reply));\n    return Ok();\n}\n","lang":"csharp"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"multi-channel-handling","__idx":9},"children":["Multi-channel handling"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["getChannel()"]}," to branch per channel:"]},{"$$mdtype":"Tag","name":"Tabs","attributes":{"size":"medium"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"label":"Node.js","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"async handleMessageInbound(event: MessageInboundEvent): Promise<void> {\n  const channel = getChannel(event);\n  const text = getText(event);\n\n  if (channel === 'WHATSAPP') {\n    await this.conversation!.messages.send({\n      sendMessageRequestBody: this.reply(event, `WhatsApp: ${text}`),\n    });\n  } else if (channel === 'SMS') {\n    const shortReply = (text ?? '').substring(0, 100);\n    await this.conversation!.messages.send({\n      sendMessageRequestBody: this.reply(event, shortReply),\n    });\n  } else {\n    await this.conversation!.messages.send({\n      sendMessageRequestBody: this.reply(event, `Got your message on ${channel}.`),\n    });\n  }\n}\n","lang":"typescript"},"children":[]}]},{"$$mdtype":"Tag","name":"div","attributes":{"label":"C#","disable":false},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"csharp","header":{"controls":{"copy":{}}},"source":"public override async Task<IActionResult> MessageInbound(MessageInboundEvent inbound)\n{\n    var channel = inbound.GetChannel();\n    var text = inbound.GetText() ?? \"\";\n\n    var reply = channel switch\n    {\n        \"WHATSAPP\" => $\"WhatsApp: {text}\",\n        \"SMS\"      => text.Length > 100 ? text[..100] : text,\n        _          => $\"Got your message on {channel}.\"\n    };\n\n    await Context.Conversation!.Messages.Send(Reply(inbound, reply));\n    return Ok();\n}\n","lang":"csharp"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"webhook-endpoint","__idx":10},"children":["Webhook endpoint"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The conversation webhook is at ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /webhook/conversation"]}," (C#) or via ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["handler.getWebhookHandler()"]}," (Node.js). Configure this URL in the Sinch Dashboard under your Conversation app's webhook settings."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For sinch.json configuration and environment variables, see ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"#"},"children":["Templates"]}," and ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"#"},"children":["Configuration & Secrets"]},"."]}]},"headings":[{"value":"Build an SMS Responder","id":"build-an-sms-responder","depth":1},{"value":"Prerequisites","id":"prerequisites","depth":2},{"value":"Basic responder","id":"basic-responder","depth":2},{"value":"Helper functions","id":"helper-functions","depth":2},{"value":"Sending replies","id":"sending-replies","depth":2},{"value":"Simple text reply","id":"simple-text-reply","depth":3},{"value":"Send to a specific contact by ID","id":"send-to-a-specific-contact-by-id","depth":3},{"value":"Send via explicit channel (SMS)","id":"send-via-explicit-channel-sms","depth":3},{"value":"Keyword-based routing","id":"keyword-based-routing","depth":2},{"value":"Multi-channel handling","id":"multi-channel-handling","depth":2},{"value":"Webhook endpoint","id":"webhook-endpoint","depth":2}],"frontmatter":{"seo":{"title":""}},"lastModified":"2026-04-15T14:23:23.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/functions/guides/build-an-sms-responder","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}