Send a Message to Telegram using 🤔PHP🤞

KARTHIK M
YavarTechWorks
Published in
3 min readOct 20, 2022

--

let me tell you!! 👉To send a message to a Telegram channel using PHP, you need to know a Telegram API token and a chat ID, that you will get when you create a Telegram bot.

How to create the Telegram Bot🤖🤖

Start a conversation with the BotFather:

Step 1:GLOBAL SEARCH -> BotFather

BotFather: The BotFather is the one bot to rule them all. Use it to create new bot accounts and manage your existing bots.

Create a new bot:

Step 2:/newbot

Choose a user-friendly name for your bot also should be unique (must end with “bot”), for example:

Step 3:Atom_Bot

Once the bot is created, you will get a token to access the Telegram API.

TOKEN: The token is a string that is required to authorize the bot and send requests to the Telegram API, e.g. 4334584910:AAEPmjlh84N62Lv3jGWEgOftlxxAfMhB1gs

So, This is how you can able to create the Bot. Now you need to create the Telegram channel.

Creating a Telegram channel on Android is pretty easy. Follow the steps below to create your channel on Telegram:

  1. Open Telegram 📲on your Android device.
  2. Click on the pen icon at the bottom of the screen and select New Channel on the following screen.

3. Enter a name for your channel in the Channel name field. Optionally, you can add a description to describe your Telegram channel if you feel so.

4. Tap on the camera icon adjacent to your channel name and select a picture as the display picture for your Telegram picture.

5. Tap the tick button on the top-right corner.

6. Select the Channel type between Public Channel or Private Channel depending on what kind of channel you want to create.

7. If it’s a public channel, set a permanent link for your channel. This link is what people would use to search for and join your channel.

8. Tap the tick icon again to confirm.

9. Telegram will ask you to add subscribers to your Telegram channel, and select the contacts you’d like to add. This is optional, and you can choose not to add any members for now.

10. Tap the right-pointing arrow👉🏹 to continue and create your channel on Telegram.

Once you have created the channel you should add the created Bot(Atom_bot) and make it an Admin

In a Telegram group, to promote a member to an Admin, you can follow any of the following two methods:

Method 1:

• Open the Member list

• Tap and hold on to that member that you want to promote to an admin, two options will pop up on the screen.

• Tap on Promote to admin

Method 2:

• Open Group info and tap on three vertical dots in the top right corner and tap Edit

• Tap on Administrators

• Tap on Add Administrator and select the member that you want to add as an admin.

To send a message to the Telegram channel use the following PHP script:)

<?php 
$apiToken = “4334584910:AAEPmjlh84N62Lv3jGWEgOftlxxAfMhB1gs”;

$data = [
‘chat_id’ => ‘@demo’,
‘text’ => ‘Welcome to my world’
];

$response = file_get_contents(“http://api.telegram.org/bot$apiToken/sendMessage?" . http_build_query($data) );
?>

Yeah, we have completed the process successfully✨!

Wishing you a very happy learning …!!!$$$

--

--