{"__v":12,"_id":"56a265120aefae0d00b7fe44","category":{"__v":9,"_id":"56b200c0f48f270d00e0de6f","pages":["56b201173b6f690d00bdb68e","56b20ef3bf040b0d00588be4","56b214097ae4550d00062928","56b21502bf040b0d00588bea","56c1ffb1d07cc50d005e5f5e","56c74a05af5bc40d00d6bb5b","56d412b38001e30b00896dd5","56d85fc1c83c5f0b00d288a2","56d866f4a957fb1500765a40"],"project":"568fce2a04440a1700e4cb47","version":"568fce2b04440a1700e4cb4a","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-03T13:29:36.476Z","from_sync":false,"order":1,"slug":"c","title":"C# Quickstarts"},"parentDoc":null,"project":"568fce2a04440a1700e4cb47","user":"55116f88e2990b0d00fb0552","version":{"__v":20,"_id":"568fce2b04440a1700e4cb4a","project":"568fce2a04440a1700e4cb47","createdAt":"2016-01-08T14:56:43.101Z","releaseDate":"2016-01-08T14:56:43.101Z","categories":["568fce2b04440a1700e4cb4b","568fd1b8b700ce0d002f4b1c","568fd23804440a1700e4cb5b","568fd2444719c119002ce5d8","568ff21204440a1700e4cbc1","5693732c8aa8040d009f2c28","5693738393445b0d00abdad0","5693740093445b0d00abdad1","56937445974aaa0d001ca699","5693b82173f48f0d0075c90d","5694c4cd1005590d0062cb25","569f854466a5640d00efa54c","56a264cdd15dd70d008d825b","56aa56bf318e6c1700a19ddb","56b0e6347ae4550d000627bd","56b200c0f48f270d00e0de6f","56b200c6f48f270d00e0de70","56b22a9665ddf50d0076ba40","56e92ef71996862200fd7f42","574d6577fb835c0e00ca316a"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-01-22T17:21:22.565Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Note\",\n  \"body\": \"You will need a Dynmark long number or shortcode keyword attached to your account to be able to work through this quickstart.\"\n}\n[/block]\nIn the last Receive SMS Messages quickstart, we processed sent message receipts. Now that our target audience has received a message, they're going to want to reply. We can handle the replies using Inbound Message Forwarding.\n\nSimilar to the last sample, we're going to create an inbound message handler that logs each message to an in memory data store.\n\n1.Create InboundHandler.cshtml which will receive and process inbound messages\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \":::at:::functions {\\n    public class InboundMessage\\n    {\\n        public long MessageId { get; set; }\\n        public DateTime Date { get; set; }\\n        public string Sender { get; set; }\\n        public string Recipient { get; set; }\\n        public string Body { get; set; }\\n    }\\n\\n    public class InboundStore\\n    {\\n        public static Dictionary<long, InboundMessage> Messages =\\n        \\t\\tnew Dictionary<long, InboundMessage>();\\n    }\\n}\\n\\n@{\\n    // Do some basic parameter validation before processing\\n    if (!string.IsNullOrEmpty(Request[\\\"msgid\\\"]))\\n    {\\n        var messageId = long.Parse(Request[\\\"msgid\\\"]);\\n        InboundStore.Messages[messageId] =\\n            new InboundMessage\\n            {\\n                MessageId = messageId,\\n                Date = DateTime.Parse(Request[\\\"datetime\\\"]),\\n                Recipient = Request[\\\"recipient\\\"],\\n                Sender = Request[\\\"sender\\\"],\\n                Body = Request[\\\"content\\\"]\\n            };\\n    }\\n}\\n\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nWe log the date the Dynmark generated numeric message id, the date the message arrived, the phone number that the message was from, the Dynmark long number it was sent to and the body of the message.\n\nWe now need to enable the sending of inbound messages to our new handler by visiting the Dynmark User Portal [Inbound Settings](https://stage-apps.dynmark.com/DD/UserPortal/Home/IncomingForwarding) page and adding your inbound message handler endpoint to the Dynmark long number or keyword.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Note\",\n  \"body\": \"The inbound message handler endpoint specified must be publicly accessible\"\n}\n[/block]\n3.Finally, create InboundViewer.cshtml which will allow us to view the messages we've received.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<table>\\n    <tr>\\n        <th>MessageId</th>\\n        <th>Date</th>\\n        <th>Sender</th>\\n        <th>Recipient</th>\\n        <th>Body</th>\\n    </tr>\\n    @foreach (var message in _Page_InboundHandler_cshtml.InboundStore.Messages.Values)\\n    {\\n        <tr>\\n            <td>@message.MessageId</td>\\n            <td>@message.Date</td>\\n            <td>@message.Sender</td>\\n            <td>@message.Recipient</td>\\n            <td>@message.Body</td>\\n        </tr>}\\n</table>\\n\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]","excerpt":"Receiving text messages via inbound message forwarding","slug":"qs-cs-receive-sms-messages","type":"basic","title":"Receive SMS Messages"}

Receive SMS Messages

Receiving text messages via inbound message forwarding

[block:callout] { "type": "info", "title": "Note", "body": "You will need a Dynmark long number or shortcode keyword attached to your account to be able to work through this quickstart." } [/block] In the last Receive SMS Messages quickstart, we processed sent message receipts. Now that our target audience has received a message, they're going to want to reply. We can handle the replies using Inbound Message Forwarding. Similar to the last sample, we're going to create an inbound message handler that logs each message to an in memory data store. 1.Create InboundHandler.cshtml which will receive and process inbound messages [block:code] { "codes": [ { "code": "@functions {\n public class InboundMessage\n {\n public long MessageId { get; set; }\n public DateTime Date { get; set; }\n public string Sender { get; set; }\n public string Recipient { get; set; }\n public string Body { get; set; }\n }\n\n public class InboundStore\n {\n public static Dictionary<long, InboundMessage> Messages =\n \t\tnew Dictionary<long, InboundMessage>();\n }\n}\n\n@{\n // Do some basic parameter validation before processing\n if (!string.IsNullOrEmpty(Request[\"msgid\"]))\n {\n var messageId = long.Parse(Request[\"msgid\"]);\n InboundStore.Messages[messageId] =\n new InboundMessage\n {\n MessageId = messageId,\n Date = DateTime.Parse(Request[\"datetime\"]),\n Recipient = Request[\"recipient\"],\n Sender = Request[\"sender\"],\n Body = Request[\"content\"]\n };\n }\n}\n", "language": "csharp" } ] } [/block] We log the date the Dynmark generated numeric message id, the date the message arrived, the phone number that the message was from, the Dynmark long number it was sent to and the body of the message. We now need to enable the sending of inbound messages to our new handler by visiting the Dynmark User Portal [Inbound Settings](https://stage-apps.dynmark.com/DD/UserPortal/Home/IncomingForwarding) page and adding your inbound message handler endpoint to the Dynmark long number or keyword. [block:callout] { "type": "info", "title": "Note", "body": "The inbound message handler endpoint specified must be publicly accessible" } [/block] 3.Finally, create InboundViewer.cshtml which will allow us to view the messages we've received. [block:code] { "codes": [ { "code": "<table>\n <tr>\n <th>MessageId</th>\n <th>Date</th>\n <th>Sender</th>\n <th>Recipient</th>\n <th>Body</th>\n </tr>\n @foreach (var message in _Page_InboundHandler_cshtml.InboundStore.Messages.Values)\n {\n <tr>\n <td>@message.MessageId</td>\n <td>@message.Date</td>\n <td>@message.Sender</td>\n <td>@message.Recipient</td>\n <td>@message.Body</td>\n </tr>}\n</table>\n", "language": "csharp" } ] } [/block]