{"_id":"56b214097ae4550d00062928","__v":6,"parentDoc":null,"user":"55116f88e2990b0d00fb0552","project":"568fce2a04440a1700e4cb47","version":{"_id":"568fce2b04440a1700e4cb4a","project":"568fce2a04440a1700e4cb47","__v":20,"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"},"category":{"_id":"56b200c6f48f270d00e0de70","pages":["56b22b962d96461700599228","56b3240705daaa2300363143","56b33a9978a12121009006a1","56b33ab2af176a0d00964ce1","56cae5309f4ae20b00644dca","56d412878001e30b00896dd2","56d6c28947f18a2d0088d620","56d87228a957fb1500765a63"],"project":"568fce2a04440a1700e4cb47","version":"568fce2b04440a1700e4cb4a","__v":8,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-03T13:29:42.367Z","from_sync":false,"order":2,"slug":"node","title":"Node.js Quickstarts"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-03T14:51:53.061Z","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.js which will receive and process inbound messages\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var express = require('express');\\nvar router = express.Router();\\nglobal.inbound = {};\\n\\n/* GET users listing. */\\nrouter.get('/inboundHandler', function(req, res, next) {\\n    var queryData = req.query;\\n    var messageId = parseInt(queryData.msgid);\\n    \\n    global.inbound[messageId] = {\\n        messageId: messageId,\\n        date: queryData.datetime,\\n        recipient: queryData.recipient,\\n        sender: queryData.sender,\\n        body: queryData.content\\n    };\\n        \\n    res.writeHead(200, {\\\"Content-Type\\\": \\\"text/html\\\"});\\n    res.end();\\n});\\n\\nmodule.exports = router;\\n\",\n      \"language\": \"javascript\"\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://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. Add a jade view called inboundViewer.jade which will allow us to view the messages we've received.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"extends layout\\n\\nblock content\\n    table\\n        thead\\n            th MessageId\\n            th Date\\n            th Sender\\n            th Recipient\\n            th Body\\n        tbody\\n            each val in global.inbound\\n                tr\\n                    td= val.messageId\\n                    td= val.date\\n                    td= val.sender\\n                    td= val.recipient\\n                    td= val.body\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n4.Finally, create inboundViewer.js which will plumb the new view\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var express = require('express');\\nvar router = express.Router();\\n\\nrouter.get('/inboundViewer', function(req, res, next) {\\n  res.render('inboundViewer');\\n});\\n\\nmodule.exports = router;\\n\",\n      \"language\": \"javascript\",\n      \"name\": \"jade\"\n    }\n  ]\n}\n[/block]","excerpt":"Receiving text messages via inbound message forwarding","slug":"qs-node-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.js which will receive and process inbound messages [block:code] { "codes": [ { "code": "var express = require('express');\nvar router = express.Router();\nglobal.inbound = {};\n\n/* GET users listing. */\nrouter.get('/inboundHandler', function(req, res, next) {\n var queryData = req.query;\n var messageId = parseInt(queryData.msgid);\n \n global.inbound[messageId] = {\n messageId: messageId,\n date: queryData.datetime,\n recipient: queryData.recipient,\n sender: queryData.sender,\n body: queryData.content\n };\n \n res.writeHead(200, {\"Content-Type\": \"text/html\"});\n res.end();\n});\n\nmodule.exports = router;\n", "language": "javascript" } ] } [/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://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. Add a jade view called inboundViewer.jade which will allow us to view the messages we've received. [block:code] { "codes": [ { "code": "extends layout\n\nblock content\n table\n thead\n th MessageId\n th Date\n th Sender\n th Recipient\n th Body\n tbody\n each val in global.inbound\n tr\n td= val.messageId\n td= val.date\n td= val.sender\n td= val.recipient\n td= val.body", "language": "text" } ] } [/block] 4.Finally, create inboundViewer.js which will plumb the new view [block:code] { "codes": [ { "code": "var express = require('express');\nvar router = express.Router();\n\nrouter.get('/inboundViewer', function(req, res, next) {\n res.render('inboundViewer');\n});\n\nmodule.exports = router;\n", "language": "javascript", "name": "jade" } ] } [/block]