Docs

Sending the messages to your contacts in Telegram

Step 1. Prerequisites

1. Register at apifonica.com and create an Apifonica account, if you have not done so already.

2. Rent an Apifonica mobile phone number to be used for Telegram.

You can find instructions on registering Apifonica accounts and renting numbers here.

3. Send a request to support@apifonica.com to register your number for Telegram usage (mandatory step!)
After receiving confirmation from the support, your number is ready for use

Step 2. Creating the recipient's database

You can send the messages only to the contacts, that are added to your contact list. Make the PUT request to https://msapi.apifonica.com/v2/accounts/{account_sid}/messengers/telegram/{number}/contacts with all the numbers from your list (Details - in the article Add contacts to Telegram number).
In one request you are adding to the contact list of your recipients and checking the presence in Telegram. All the contacts that have an account in Telegram will be added and all, that are not present, will be listed in error array:

{
    "status_code": 200,
    "status_message": "OK",
    "errors": [
        "358987654321"
    ]
}

Step 3. Sending the message to Telegram

Make the POST request to https://api.apifonica.com/v2/accounts/{accountSID}/messages choosing "channel": "telegram" parameter.

The following cURL example demonstrates sending a message with GIF content to Telegram:

curl –X POST ‘https://api.apifonica.com/v2/accounts/{accountSID}/messages’ \
-H ‘Content-Type: application/json’ \
-d ‘{ \
     "from": "35315313424", \
     "to": "447860041755", \
     "channel": "telegram", \
     "type": "gif", \
     "url": "https://media.giphy.com/media/ya4eevXU490Iw/giphy.gif", \
     "text": "Apifonica API provides a really cool SMS messaging service" \
    }' \
-u {accountSID}:{authToken}