{"__v":0,"_id":"584fc3957627093b00ce7595","category":{"__v":8,"_id":"56669e857cc81e0d00253f8e","pages":["568ceacb8a7ca5190039643a","5693a7995f1c951900644b25","5698e793d36db20d00ddba45","56a0ce7441766e0d00b28cf8","56a0d36544f3d80d00a2c242","56a0d3e0aca0730d003e3475","56a5ecf7b91d8d0d008349cc","56d595dba0b5600b000b1e75"],"project":"54eb50e5615ffc1900305a16","version":"54eb63b859b1172100334fae","sync":{"url":"","isSync":false},"reference":true,"createdAt":"2015-12-08T09:10:29.254Z","from_sync":false,"order":4,"slug":"omni-channel-messaging","title":"OMNI channel messaging"},"parentDoc":null,"project":"54eb50e5615ffc1900305a16","user":"582ddb2f8653af2d00f5a9c5","version":{"__v":20,"_id":"54eb63b859b1172100334fae","forked_from":"54eb63a1867e1917009b711d","project":"54eb50e5615ffc1900305a16","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"],"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-13T09:47:01.754Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":true,"order":11,"body":"[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Prerequisites\",\n  \"body\": \"To be able to send Facebook messages using Infobip platform you need to have configured the Facebook service. Please follow the [detailed instructions](doc:facebook-messenger-introduction) for service activation and configuration.\"\n}\n[/block]\nIn the following examples we'll show you how to configure the Facebook Messenger - SMS OMNI failover scenario, send your first messages and retrieve message reports. \n\nThere are three easy steps to follow: \n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Facebook Messenger - SMS OMNI process\",\n  \"body\": \"1. Create an OMNI Scenario\\n2. Send message using an OMNI scenario\\n3. Get Delivery Reports\"\n}\n[/block]\nAvailable methods:\n* [Create OMNI scenario](#create-an-omni-scenario)\n* [Send OMNI text message](#send-omni-text-message)\n* [Send OMNI message by using Facebook user key](#send-omni-message-by-using-facebook-user-key)\n* [Send rich OMNI message](#send-rich-omni-message)\n* [Get delivery reports](#get-delivery-reports) \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Create an OMNI scenario\"\n}\n[/block]\nThe first step is to create an  **OMNI scenario**. In the OMNI scenario configuration, you need to define the OMNI steps which will be sequentially executed. The key parameters are the **`channel`** and **`from`**, respectively identifying the communication channels and senders for each communication channel.\n\nFor Facebook sender (**\"channel\": \"FACEBOOK\"** flow) You should use the Facebook application **`key`** obtained during the Facebook channel activation process.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"POST /omni/1/scenarios HTTP/1.1\\nHost: api.infobip.com\\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\\nContent-Type: application/json\\n\\n{\\n  \\\"name\\\":\\\"My first Facebook-SMS scenario\\\",\\n  \\\"flow\\\": [\\n    {\\n      \\\"from\\\": \\\"FacebookApplicationKey\\\",\\n      \\\"channel\\\": \\\"FACEBOOK\\\"\\n    },\\n    {\\n      \\\"from\\\": \\\"InfoSMS\\\",\\n      \\\"channel\\\": \\\"SMS\\\"\\n    }    \\n  ],\\n  \\\"default\\\": true\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nResponse\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"key\\\": \\\"12CD1116DC7B451B2B7286412482CCC1\\\",\\n  \\\"name\\\":\\\"My first Facebook-SMS scenario\\\",\\n  \\\"flow\\\": [\\n    {\\n      \\\"from\\\": \\\"FacebookApplicationKey\\\",\\n      \\\"channel\\\": \\\"FACEBOOK\\\"\\n    },\\n    {\\n      \\\"from\\\": \\\"InfoSMS\\\",\\n      \\\"channel\\\": \\\"SMS\\\"\\n    }    \\n  ],\\n  \\\"default\\\": true\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nIf successful, the response header HTTP status code will be `200 OK` and the scenario will be created, as shown in the example bellow. If you try to create the scenario without authorization, you will receive a `401 Unauthorized` error.\n\nThe **`key`** parameter needs to be stored as it will be used when sending the OMNI message.\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Info\",\n  \"body\": \"More information about creating an OMNI scenario can be found at the following page: [Scenario: Create](doc:omni-create-scenario).\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"post\",\n  \"title\": \"Send OMNI text message\"\n}\n[/block]\nOnce You've created an OMNI scenario (identified by the **`key`** parameter) as described in the previous chapter, you are ready to send your OMNI messages through defined FACEBOOK and SMS communication channels. Firstly, the FACEBOOK message will be sent on the defined phoneNumber. If for some reason the message is rejected on the FACEBOOK platform, the message will be sent using the SMS communication channel.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Facebook messenger phone number\",\n  \"body\": \"To be able to send messages to Facebook Messenger users, using the phone number, certain guidelines provided by Facebook must be followed. Please check detailed [Facebook guidelines](https://developers.facebook.com/docs/messenger-platform/send-api-reference#phone_number)\"\n}\n[/block]\nFor sending OMNI messages, you can use the **advanced** API method. Detailed descriptions about the **advanced** API method can be found here: [OMNI: Send the advanced message](doc:omni-send-advanced-message). \n\nThe parameters that should be set are the scenario key, phoneNumber and specific text for each communication channels, as shown below. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"POST /omni/1/advanced HTTP/1.1\\nHost: api.infobip.com\\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\\nContent-Type: application/json\\n\\n{ \\n\\t\\\"scenarioKey\\\":\\\"CC9F01A5DC7BEE2C2B829D203482A654\\\",  \\n  \\\"destinations\\\":[ \\n  \\t{ \\n    \\t\\\"to\\\":{\\n        \\\"phoneNumber\\\": \\\"41793026727\\\"\\n      }\\n    }\\n  ],\\n  \\\"facebook\\\": {\\n  \\t\\\"text\\\": \\\"This Facebook message will be delivered both to the Facebook user page and Facebook messenger.\\\"\\n  },\\n  \\\"sms\\\": {\\n  \\t\\\"text\\\": \\\"This is the SMS failover message\\\"\\n  }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nThe response:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{   \\n    \\\"messages\\\":[   \\n       {   \\n            \\\"to\\\":{\\n              \\\"phoneNumber\\\": \\\"41793026731\\\"\\n            },\\n            \\\"status\\\":{   \\n                \\\"groupId\\\":0,\\n                \\\"groupName\\\":\\\"ACCEPTED\\\",\\n                \\\"id\\\":0,\\n                \\\"name\\\":\\\"MESSAGE_ACCEPTED\\\",\\n                \\\"description\\\":\\\"Message accepted\\\"\\n            },\\n            \\\"messageId\\\":\\\"1215f543ab19-345f-adbd-12ad31451ed25f35\\\"\\n        }\\n    ]\\n}\",\n      \"language\": \"json\",\n      \"name\": \"200 OK\"\n    }\n  ]\n}\n[/block]\nIf successful, the response header HTTP status code will be `200 OK` and the message will be sent. If you try to send the message without authorization, you will receive a `401 Unauthorized` error.\n[block:api-header]\n{\n  \"type\": \"post\",\n  \"title\": \"Send OMNI message by using Facebook user key\"\n}\n[/block]\nThe phone number is not the only way to identify the recipient of the message. In some cases, your user may be using one phone number for receiving SMS messages and the other which is registered on Facebook. If this is the case, specifying one recipient phone number is not enough.\n\nThis is where `facebookUserKey` comes in handy. If Facebook User Key is specified, it will be used as primary destination address for the Facebook message. The `phoneNumber` will be used only as SMS destination.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Facebook User Key\",\n  \"body\": \"Each registered application user has a unique 'key' which can be used as Facebook messenger destination address. Learn how to access your user keys in [**User documentation**](/docs/facebook-messenger-user).\"\n}\n[/block]\nRequest example\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"POST /omni/1/advanced HTTP/1.1\\nHost: api.infobip.com\\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\\nContent-Type: application/json\\n\\n{ \\n\\t\\\"scenarioKey\\\":\\\"CC9F01A5DC7BEE2C2B829D203482A654\\\",  \\n  \\\"destinations\\\":[ \\n  \\t{ \\n    \\t\\\"to\\\":{\\n        \\\"phoneNumber\\\": \\\"41793026727\\\",\\n        \\\"facebookUserKey\\\": \\\"9c29bd43-054b-4cfe-a1d4-0b37812b4ed3\\\"\\n      }\\n    }\\n  ],\\n  \\\"facebook\\\": {\\n  \\t\\\"text\\\": \\\"This Facebook message will be delivered both to the Facebook user page and Facebook messenger.\\\"\\n  },\\n  \\\"sms\\\": {\\n  \\t\\\"text\\\": \\\"This is the SMS failover message\\\"\\n  }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nThe response\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{   \\n    \\\"messages\\\":[   \\n       {   \\n            \\\"to\\\":{\\n              \\\"phoneNumber\\\": \\\"41793026731\\\",\\n              \\\"facebookUserKey\\\": \\\"9c29bd43-054b-4cfe-a1d4-0b37812b4ed3\\\"\\n            },\\n            \\\"status\\\":{   \\n                \\\"groupId\\\":0,\\n                \\\"groupName\\\":\\\"ACCEPTED\\\",\\n                \\\"id\\\":0,\\n                \\\"name\\\":\\\"MESSAGE_ACCEPTED\\\",\\n                \\\"description\\\":\\\"Message accepted\\\"\\n            },\\n            \\\"messageId\\\":\\\"1215f543ab19-345f-adbd-12ad31451ed25f35\\\"\\n        }\\n    ]\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"post\",\n  \"title\": \"Send rich OMNI message\"\n}\n[/block]\nBesides the text message, the media file can also be sent over API. Before sending the message, you will need to upload your media to publicly accessible server and supply `url` of the file.\n\nAccording to supplied file type, Facebook will attempt to render media preview inside of the client chat application. \n\nSupported media types are: `IMAGE`, `AUDIO`, `VIDEO` and `FILE`.\n\nIf `type` is defined, `url` of the file must also be included in the request.\n\nImage request example:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"POST /omni/1/advanced HTTP/1.1\\nHost: api.infobip.com\\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\\nContent-Type: application/json\\n\\n{ \\n\\t\\\"scenarioKey\\\":\\\"CC9F01A5DC7BEE2C2B829D203482A654\\\",  \\n  \\\"destinations\\\":[ \\n  \\t{ \\n    \\t\\\"to\\\":{\\n        \\\"phoneNumber\\\": \\\"41793026727\\\"\\n      }\\n    }\\n  ],\\n  \\\"facebook\\\": {\\n    \\\"type\\\": \\\"IMAGE\\\",\\n    \\\"url\\\": \\\"https://somedomain.com/images/image.jpg\\\"\\n  },\\n  \\\"sms\\\": {\\n  \\t\\\"text\\\": \\\"This is the SMS failover message\\\"\\n  }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nResponse:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{   \\n    \\\"messages\\\":[   \\n       {   \\n            \\\"to\\\":{\\n              \\\"phoneNumber\\\": \\\"41793026731\\\"\\n            },\\n            \\\"status\\\":{   \\n                \\\"groupId\\\":0,\\n                \\\"groupName\\\":\\\"ACCEPTED\\\",\\n                \\\"id\\\":0,\\n                \\\"name\\\":\\\"MESSAGE_ACCEPTED\\\",\\n                \\\"description\\\":\\\"Message accepted\\\"\\n            },\\n            \\\"messageId\\\":\\\"1215f543ab19-345f-adbd-12ad31451ed25f35\\\"\\n        }\\n    ]\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"get\",\n  \"title\": \"Get Delivery Reports\"\n}\n[/block]\nOnce you've successfully sent your message using the **advanced** API method you'll be able to check the status of sent messages using the [OMNI reports](doc:omni-reports) method. \n\nThe simplest way is to use the method without any query parameters. In that case, the response will contain all the messages sent to a specific account.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"GET /omni/1/reports HTTP/1.1\\nHost: api.infobip.com\\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\\nAccept: application/json\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nThe response will contain all messages, rejected and delivered, as shown in the example below.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"HTTP/1.1 200 OK\\nContent-Type: application/json\\n\\n{  \\n   \\\"results\\\":[  \\n      {  \\n         \\\"messageId\\\":\\\"1215f543ab19-345f-adbd-12ad31451ed25f35\\\",\\n         \\\"to\\\":\\\"41793026731\\\",\\n         \\\"messageCount\\\": 1,\\n         \\\"sentAt\\\":\\\"2016-02-23T17:41:11.833+0100\\\",\\n         \\\"doneAt\\\":\\\"2016-02-23T17:41:11.843+0100\\\",\\n         \\\"mccMnc\\\":\\\"22801\\\",\\n         \\\"price\\\":{  \\n            \\\"pricePerMessage\\\":0.0104,\\n            \\\"currency\\\":\\\"EUR\\\"\\n         },\\n         \\\"status\\\":{  \\n            \\\"groupId\\\":2,\\n            \\\"groupName\\\":\\\"UNDELIVERABLE\\\",\\n            \\\"id\\\":9,\\n            \\\"name\\\":\\\"UNDELIVERABLE_NOT_DELIVERED\\\",\\n            \\\"description\\\":\\\"Message sent not delivered\\\"\\n         },\\n         \\\"error\\\":{  \\n            \\\"groupId\\\":1,\\n            \\\"groupName\\\":\\\"HANDSET_ERRORS\\\",\\n            \\\"id\\\":6,\\n            \\\"name\\\":\\\"EC_ABSENT_SUBSCRIBER_SM\\\",\\n            \\\"description\\\":\\\"Absent Subscriber\\\",\\n            \\\"permanent\\\":false\\n         },\\n        \\\"channel\\\": \\\"FACEBOOK\\\"\\n      },\\n      {  \\n         \\\"messageId\\\":\\\"2315d543441c-335f-1d3d-142d31451ed25f35\\\",\\n         \\\"to\\\":\\\"41793026731\\\",\\n         \\\"sentAt\\\":\\\"2016-06-23T17:40:31.773+0100\\\",\\n         \\\"doneAt\\\":\\\"2016-06-23T17:40:31.787+0100\\\",\\n         \\\"messageCount\\\":1,\\n         \\\"mccMnc\\\":\\\"22801\\\",\\n         \\\"price\\\":{  \\n            \\\"pricePerMessage\\\":0.01,\\n            \\\"currency\\\":\\\"EUR\\\"\\n         },\\n         \\\"status\\\":{  \\n            \\\"groupId\\\":3,\\n            \\\"groupName\\\":\\\"DELIVERED\\\",\\n            \\\"id\\\":5,\\n            \\\"name\\\":\\\"DELIVERED_TO_HANDSET\\\",\\n            \\\"description\\\":\\\"Message delivered to handset\\\"\\n         },\\n         \\\"error\\\":{  \\n            \\\"groupId\\\":0,\\n            \\\"groupName\\\":\\\"OK\\\",\\n            \\\"id\\\":0,\\n            \\\"name\\\":\\\"NO_ERROR\\\",\\n            \\\"description\\\":\\\"No Error\\\",\\n            \\\"permanent\\\":false\\n         },\\n        \\\"channel\\\": \\\"SMS\\\"\\n      }\\n   ]\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]","excerpt":"This page will describe simple methods which will allow You to send messages and retrieve message reports using the Facebook and SMS communication channels.","slug":"omni-channel-facebook-messenger-example","type":"basic","title":"OMNI channel: Facebook example"}

OMNI channel: Facebook example

This page will describe simple methods which will allow You to send messages and retrieve message reports using the Facebook and SMS communication channels.

[block:callout] { "type": "warning", "title": "Prerequisites", "body": "To be able to send Facebook messages using Infobip platform you need to have configured the Facebook service. Please follow the [detailed instructions](doc:facebook-messenger-introduction) for service activation and configuration." } [/block] In the following examples we'll show you how to configure the Facebook Messenger - SMS OMNI failover scenario, send your first messages and retrieve message reports. There are three easy steps to follow: [block:callout] { "type": "info", "title": "Facebook Messenger - SMS OMNI process", "body": "1. Create an OMNI Scenario\n2. Send message using an OMNI scenario\n3. Get Delivery Reports" } [/block] Available methods: * [Create OMNI scenario](#create-an-omni-scenario) * [Send OMNI text message](#send-omni-text-message) * [Send OMNI message by using Facebook user key](#send-omni-message-by-using-facebook-user-key) * [Send rich OMNI message](#send-rich-omni-message) * [Get delivery reports](#get-delivery-reports) [block:api-header] { "type": "basic", "title": "Create an OMNI scenario" } [/block] The first step is to create an **OMNI scenario**. In the OMNI scenario configuration, you need to define the OMNI steps which will be sequentially executed. The key parameters are the **`channel`** and **`from`**, respectively identifying the communication channels and senders for each communication channel. For Facebook sender (**"channel": "FACEBOOK"** flow) You should use the Facebook application **`key`** obtained during the Facebook channel activation process. [block:code] { "codes": [ { "code": "POST /omni/1/scenarios HTTP/1.1\nHost: api.infobip.com\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\nContent-Type: application/json\n\n{\n \"name\":\"My first Facebook-SMS scenario\",\n \"flow\": [\n {\n \"from\": \"FacebookApplicationKey\",\n \"channel\": \"FACEBOOK\"\n },\n {\n \"from\": \"InfoSMS\",\n \"channel\": \"SMS\"\n } \n ],\n \"default\": true\n}", "language": "json" } ] } [/block] Response [block:code] { "codes": [ { "code": "{\n \"key\": \"12CD1116DC7B451B2B7286412482CCC1\",\n \"name\":\"My first Facebook-SMS scenario\",\n \"flow\": [\n {\n \"from\": \"FacebookApplicationKey\",\n \"channel\": \"FACEBOOK\"\n },\n {\n \"from\": \"InfoSMS\",\n \"channel\": \"SMS\"\n } \n ],\n \"default\": true\n}", "language": "json" } ] } [/block] If successful, the response header HTTP status code will be `200 OK` and the scenario will be created, as shown in the example bellow. If you try to create the scenario without authorization, you will receive a `401 Unauthorized` error. The **`key`** parameter needs to be stored as it will be used when sending the OMNI message. [block:callout] { "type": "info", "title": "Info", "body": "More information about creating an OMNI scenario can be found at the following page: [Scenario: Create](doc:omni-create-scenario)." } [/block] [block:api-header] { "type": "post", "title": "Send OMNI text message" } [/block] Once You've created an OMNI scenario (identified by the **`key`** parameter) as described in the previous chapter, you are ready to send your OMNI messages through defined FACEBOOK and SMS communication channels. Firstly, the FACEBOOK message will be sent on the defined phoneNumber. If for some reason the message is rejected on the FACEBOOK platform, the message will be sent using the SMS communication channel. [block:callout] { "type": "warning", "title": "Facebook messenger phone number", "body": "To be able to send messages to Facebook Messenger users, using the phone number, certain guidelines provided by Facebook must be followed. Please check detailed [Facebook guidelines](https://developers.facebook.com/docs/messenger-platform/send-api-reference#phone_number)" } [/block] For sending OMNI messages, you can use the **advanced** API method. Detailed descriptions about the **advanced** API method can be found here: [OMNI: Send the advanced message](doc:omni-send-advanced-message). The parameters that should be set are the scenario key, phoneNumber and specific text for each communication channels, as shown below. [block:code] { "codes": [ { "code": "POST /omni/1/advanced HTTP/1.1\nHost: api.infobip.com\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\nContent-Type: application/json\n\n{ \n\t\"scenarioKey\":\"CC9F01A5DC7BEE2C2B829D203482A654\", \n \"destinations\":[ \n \t{ \n \t\"to\":{\n \"phoneNumber\": \"41793026727\"\n }\n }\n ],\n \"facebook\": {\n \t\"text\": \"This Facebook message will be delivered both to the Facebook user page and Facebook messenger.\"\n },\n \"sms\": {\n \t\"text\": \"This is the SMS failover message\"\n }\n}", "language": "json" } ] } [/block] The response: [block:code] { "codes": [ { "code": "{ \n \"messages\":[ \n { \n \"to\":{\n \"phoneNumber\": \"41793026731\"\n },\n \"status\":{ \n \"groupId\":0,\n \"groupName\":\"ACCEPTED\",\n \"id\":0,\n \"name\":\"MESSAGE_ACCEPTED\",\n \"description\":\"Message accepted\"\n },\n \"messageId\":\"1215f543ab19-345f-adbd-12ad31451ed25f35\"\n }\n ]\n}", "language": "json", "name": "200 OK" } ] } [/block] If successful, the response header HTTP status code will be `200 OK` and the message will be sent. If you try to send the message without authorization, you will receive a `401 Unauthorized` error. [block:api-header] { "type": "post", "title": "Send OMNI message by using Facebook user key" } [/block] The phone number is not the only way to identify the recipient of the message. In some cases, your user may be using one phone number for receiving SMS messages and the other which is registered on Facebook. If this is the case, specifying one recipient phone number is not enough. This is where `facebookUserKey` comes in handy. If Facebook User Key is specified, it will be used as primary destination address for the Facebook message. The `phoneNumber` will be used only as SMS destination. [block:callout] { "type": "warning", "title": "Facebook User Key", "body": "Each registered application user has a unique 'key' which can be used as Facebook messenger destination address. Learn how to access your user keys in [**User documentation**](/docs/facebook-messenger-user)." } [/block] Request example [block:code] { "codes": [ { "code": "POST /omni/1/advanced HTTP/1.1\nHost: api.infobip.com\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\nContent-Type: application/json\n\n{ \n\t\"scenarioKey\":\"CC9F01A5DC7BEE2C2B829D203482A654\", \n \"destinations\":[ \n \t{ \n \t\"to\":{\n \"phoneNumber\": \"41793026727\",\n \"facebookUserKey\": \"9c29bd43-054b-4cfe-a1d4-0b37812b4ed3\"\n }\n }\n ],\n \"facebook\": {\n \t\"text\": \"This Facebook message will be delivered both to the Facebook user page and Facebook messenger.\"\n },\n \"sms\": {\n \t\"text\": \"This is the SMS failover message\"\n }\n}", "language": "json" } ] } [/block] The response [block:code] { "codes": [ { "code": "{ \n \"messages\":[ \n { \n \"to\":{\n \"phoneNumber\": \"41793026731\",\n \"facebookUserKey\": \"9c29bd43-054b-4cfe-a1d4-0b37812b4ed3\"\n },\n \"status\":{ \n \"groupId\":0,\n \"groupName\":\"ACCEPTED\",\n \"id\":0,\n \"name\":\"MESSAGE_ACCEPTED\",\n \"description\":\"Message accepted\"\n },\n \"messageId\":\"1215f543ab19-345f-adbd-12ad31451ed25f35\"\n }\n ]\n}", "language": "json" } ] } [/block] [block:api-header] { "type": "post", "title": "Send rich OMNI message" } [/block] Besides the text message, the media file can also be sent over API. Before sending the message, you will need to upload your media to publicly accessible server and supply `url` of the file. According to supplied file type, Facebook will attempt to render media preview inside of the client chat application. Supported media types are: `IMAGE`, `AUDIO`, `VIDEO` and `FILE`. If `type` is defined, `url` of the file must also be included in the request. Image request example: [block:code] { "codes": [ { "code": "POST /omni/1/advanced HTTP/1.1\nHost: api.infobip.com\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\nContent-Type: application/json\n\n{ \n\t\"scenarioKey\":\"CC9F01A5DC7BEE2C2B829D203482A654\", \n \"destinations\":[ \n \t{ \n \t\"to\":{\n \"phoneNumber\": \"41793026727\"\n }\n }\n ],\n \"facebook\": {\n \"type\": \"IMAGE\",\n \"url\": \"https://somedomain.com/images/image.jpg\"\n },\n \"sms\": {\n \t\"text\": \"This is the SMS failover message\"\n }\n}", "language": "json" } ] } [/block] Response: [block:code] { "codes": [ { "code": "{ \n \"messages\":[ \n { \n \"to\":{\n \"phoneNumber\": \"41793026731\"\n },\n \"status\":{ \n \"groupId\":0,\n \"groupName\":\"ACCEPTED\",\n \"id\":0,\n \"name\":\"MESSAGE_ACCEPTED\",\n \"description\":\"Message accepted\"\n },\n \"messageId\":\"1215f543ab19-345f-adbd-12ad31451ed25f35\"\n }\n ]\n}", "language": "json" } ] } [/block] [block:api-header] { "type": "get", "title": "Get Delivery Reports" } [/block] Once you've successfully sent your message using the **advanced** API method you'll be able to check the status of sent messages using the [OMNI reports](doc:omni-reports) method. The simplest way is to use the method without any query parameters. In that case, the response will contain all the messages sent to a specific account. [block:code] { "codes": [ { "code": "GET /omni/1/reports HTTP/1.1\nHost: api.infobip.com\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\nAccept: application/json", "language": "json" } ] } [/block] The response will contain all messages, rejected and delivered, as shown in the example below. [block:code] { "codes": [ { "code": "HTTP/1.1 200 OK\nContent-Type: application/json\n\n{ \n \"results\":[ \n { \n \"messageId\":\"1215f543ab19-345f-adbd-12ad31451ed25f35\",\n \"to\":\"41793026731\",\n \"messageCount\": 1,\n \"sentAt\":\"2016-02-23T17:41:11.833+0100\",\n \"doneAt\":\"2016-02-23T17:41:11.843+0100\",\n \"mccMnc\":\"22801\",\n \"price\":{ \n \"pricePerMessage\":0.0104,\n \"currency\":\"EUR\"\n },\n \"status\":{ \n \"groupId\":2,\n \"groupName\":\"UNDELIVERABLE\",\n \"id\":9,\n \"name\":\"UNDELIVERABLE_NOT_DELIVERED\",\n \"description\":\"Message sent not delivered\"\n },\n \"error\":{ \n \"groupId\":1,\n \"groupName\":\"HANDSET_ERRORS\",\n \"id\":6,\n \"name\":\"EC_ABSENT_SUBSCRIBER_SM\",\n \"description\":\"Absent Subscriber\",\n \"permanent\":false\n },\n \"channel\": \"FACEBOOK\"\n },\n { \n \"messageId\":\"2315d543441c-335f-1d3d-142d31451ed25f35\",\n \"to\":\"41793026731\",\n \"sentAt\":\"2016-06-23T17:40:31.773+0100\",\n \"doneAt\":\"2016-06-23T17:40:31.787+0100\",\n \"messageCount\":1,\n \"mccMnc\":\"22801\",\n \"price\":{ \n \"pricePerMessage\":0.01,\n \"currency\":\"EUR\"\n },\n \"status\":{ \n \"groupId\":3,\n \"groupName\":\"DELIVERED\",\n \"id\":5,\n \"name\":\"DELIVERED_TO_HANDSET\",\n \"description\":\"Message delivered to handset\"\n },\n \"error\":{ \n \"groupId\":0,\n \"groupName\":\"OK\",\n \"id\":0,\n \"name\":\"NO_ERROR\",\n \"description\":\"No Error\",\n \"permanent\":false\n },\n \"channel\": \"SMS\"\n }\n ]\n}", "language": "json" } ] } [/block]