{"_id":"584ead2dbc5c7f1b00f039c9","__v":0,"category":{"_id":"58172386715dce0f00da4aa0","project":"54eb50e5615ffc1900305a16","version":"54eb63b859b1172100334fae","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-10-31T10:57:10.541Z","from_sync":false,"order":14,"slug":"facebook-messages","title":"Facebook messenger"},"project":"54eb50e5615ffc1900305a16","parentDoc":null,"user":"54eb4fdedf7add210007b29b","version":{"_id":"54eb63b859b1172100334fae","project":"54eb50e5615ffc1900305a16","forked_from":"54eb63a1867e1917009b711d","__v":27,"createdAt":"2015-02-23T17:30:32.501Z","releaseDate":"2015-02-23T17:30:32.501Z","categories":["54eb63b959b1172100334faf","54eb63b959b1172100334fb0","54eb63b959b1172100334fb1","54eb63b959b1172100334fb2","54ed8dd4ab373e2300f50eae","54ed99b2ab373e2300f50ede","55153a6de68daa2f00cff838","551546edbc466623002afe72","5515472ac28d6125001b8884","55154749c28d6125001b8885","555d9b4106dfec0d00d38ea7","5613e06e433e5735007c7708","5624bbb785a31117001c5403","56669e857cc81e0d00253f8e","568b8d837a42220d00498311","56a632277ef6620d00e2f18a","56d8147c3eb4dd0b00201aac","57a9ce2fac6db30e000d7efd","57a9cf4e944ea60e00dc3f74","58172386715dce0f00da4aa0","582dc59ee1b8692300c0dd03","589b19b4fec2730f0082e040","58b04a023529383900a759b5","58b92d1598157a0f004869bf","592e7685c58275000f20174f","59392839e376d4002f8a0474","59393064e376d4002f8a05a1","5947ae0d4005e2000f3a4fec","594a74df1d1de5001ab3517a","5954bc387a147f001b918915"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-12-12T13:59:09.874Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"We have covered in detail how to [send Facebook messages](/docs/send-single-facebook-messenger-message) over an API. When it comes to the reception of incoming messages from your subscribers there is a choice between two basic methods:\n  * **HTTP forward method** - allows you to receive incoming messages from your subscribers in real time\n  * **Pull method** - allows you to fetch new messages from Infobip server over an API whenever you want\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Incoming messages setup\",\n  \"body\": \"Before you can start receiving messages you need to configure for incoming messages.\\nYou can find instructions on how to setup each scenario in [Configuration documentation](/docs/facebook-messenger-configuration).\\nIt's up to you which method to use. It really depends on your use case.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"HTTP forward method\"\n}\n[/block]\nIf you wish to receive the incoming messages in real time you should use this method.\n\nIn order to receive forwarded incoming messages, you will have to set up a unique web address on your own web server that is able to receive a POST request. Every message we receive from your subscriber will be forwarded to the URL you provided in [Action setup](/docs/facebook-messenger-action).\n\nExample of the forwarded message:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"results\\\": [\\n    {\\n      \\\"from\\\": \\\"37512FEC78DBC1895567B09AE6D9439328C12E83BC83D449BC4A9F32F1AE3C3A\\\",\\n      \\\"to\\\": \\\"842C684C7856D6E876A7250135457CGE\\\",\\n      \\\"receivedAt\\\": \\\"2017-01-05T12:47:56.221+0000\\\",\\n      \\\"callbackData\\\": \\\"callbackData\\\",\\n      \\\"message\\\": {\\n        \\\"text\\\": \\\"Thank you for this!\\\",\\n        \\\"type\\\": \\\"TEXT\\\"\\n      },\\n      \\\"price\\\": {\\n        \\\"pricePerMessage\\\": 0,\\n        \\\"currency\\\": \\\"EUR\\\"\\n      }\\n    }\\n  ],\\n  \\\"messageCount\\\": 1,\\n  \\\"pendingMessageCount\\\": 0\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"get\",\n  \"title\": \"Pull method\"\n}\n[/block]\nAll messages received from your subscribers will be received on Infobip platform and will be there until you decide to access them. Accessing your received messages is pretty much straight forward. All you need to do is make simple API call which will return received messages.\n\nRequest example \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"GET /facebook/1/inbox/reports HTTP/1.1\\nHost: api.infobip.com\\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\\nAccept: application/json\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nResponse\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"results\\\": [\\n    {\\n      \\\"from\\\": \\\"37512FEC78DBC1895567B09AE6D9439328C12E83BC83D449BC4A9F32F1AE3C3A\\\",\\n      \\\"to\\\": \\\"842C684C7856D6E876A7250135457CGE\\\",\\n      \\\"receivedAt\\\": \\\"2017-01-05T12:47:56.221+0000\\\",\\n      \\\"callbackData\\\": \\\"callbackData\\\",\\n      \\\"message\\\": {\\n        \\\"text\\\": \\\"Thank you for this!\\\",\\n        \\\"type\\\": \\\"TEXT\\\"\\n      },\\n      \\\"price\\\": {\\n        \\\"pricePerMessage\\\": 0,\\n        \\\"currency\\\": \\\"EUR\\\"\\n      }\\n    }\\n  ],\\n  \\\"messageCount\\\": 1,\\n  \\\"pendingMessageCount\\\": 0\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Important\",\n  \"body\": \"All received messages can be pulled **only one time**! Once a certain message has been pulled by this method, it will not be available in the next API call. This means that every time you make an API call, you will see only messages received since the last API request you made.\"\n}\n[/block]","excerpt":"Receive incoming Facebook message from your subscribers","slug":"receive-facebook-message","type":"basic","title":"Receive Facebook message"}

Receive Facebook message

Receive incoming Facebook message from your subscribers

We have covered in detail how to [send Facebook messages](/docs/send-single-facebook-messenger-message) over an API. When it comes to the reception of incoming messages from your subscribers there is a choice between two basic methods: * **HTTP forward method** - allows you to receive incoming messages from your subscribers in real time * **Pull method** - allows you to fetch new messages from Infobip server over an API whenever you want [block:callout] { "type": "warning", "title": "Incoming messages setup", "body": "Before you can start receiving messages you need to configure for incoming messages.\nYou can find instructions on how to setup each scenario in [Configuration documentation](/docs/facebook-messenger-configuration).\nIt's up to you which method to use. It really depends on your use case." } [/block] [block:api-header] { "type": "basic", "title": "HTTP forward method" } [/block] If you wish to receive the incoming messages in real time you should use this method. In order to receive forwarded incoming messages, you will have to set up a unique web address on your own web server that is able to receive a POST request. Every message we receive from your subscriber will be forwarded to the URL you provided in [Action setup](/docs/facebook-messenger-action). Example of the forwarded message: [block:code] { "codes": [ { "code": "{\n \"results\": [\n {\n \"from\": \"37512FEC78DBC1895567B09AE6D9439328C12E83BC83D449BC4A9F32F1AE3C3A\",\n \"to\": \"842C684C7856D6E876A7250135457CGE\",\n \"receivedAt\": \"2017-01-05T12:47:56.221+0000\",\n \"callbackData\": \"callbackData\",\n \"message\": {\n \"text\": \"Thank you for this!\",\n \"type\": \"TEXT\"\n },\n \"price\": {\n \"pricePerMessage\": 0,\n \"currency\": \"EUR\"\n }\n }\n ],\n \"messageCount\": 1,\n \"pendingMessageCount\": 0\n}", "language": "json" } ] } [/block] [block:api-header] { "type": "get", "title": "Pull method" } [/block] All messages received from your subscribers will be received on Infobip platform and will be there until you decide to access them. Accessing your received messages is pretty much straight forward. All you need to do is make simple API call which will return received messages. Request example [block:code] { "codes": [ { "code": "GET /facebook/1/inbox/reports HTTP/1.1\nHost: api.infobip.com\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\nAccept: application/json", "language": "json" } ] } [/block] Response [block:code] { "codes": [ { "code": "{\n \"results\": [\n {\n \"from\": \"37512FEC78DBC1895567B09AE6D9439328C12E83BC83D449BC4A9F32F1AE3C3A\",\n \"to\": \"842C684C7856D6E876A7250135457CGE\",\n \"receivedAt\": \"2017-01-05T12:47:56.221+0000\",\n \"callbackData\": \"callbackData\",\n \"message\": {\n \"text\": \"Thank you for this!\",\n \"type\": \"TEXT\"\n },\n \"price\": {\n \"pricePerMessage\": 0,\n \"currency\": \"EUR\"\n }\n }\n ],\n \"messageCount\": 1,\n \"pendingMessageCount\": 0\n}", "language": "json" } ] } [/block] [block:callout] { "type": "warning", "title": "Important", "body": "All received messages can be pulled **only one time**! Once a certain message has been pulled by this method, it will not be available in the next API call. This means that every time you make an API call, you will see only messages received since the last API request you made." } [/block]