Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a message to a public Telegram channel by php?

Tags:

php

api

Is it possible to send a message to a public Telegram channel by API as admin? I mean is it possible to send e.g. a video to a public Telegram channel by using e.g. php?

like image 644
user3416269 Avatar asked Jan 04 '16 09:01

user3416269


People also ask

Is there an API for Telegram?

We offer two kinds of APIs for developers. The Bot API allows you to easily create programs that use Telegram messages for an interface. The Telegram API and TDLib allow you to build your own customized Telegram clients.

Can I add bot to Telegram channel?

If you have already connected bots, go to the "Manage bots" section, and click Add bot. You can also click "Connect" next to the channel. In the "Telegram" section enter your token from the necessary bot and click “Connect.” In the next window click the “Subscribe” button.


1 Answers

You can create a telegram bot and add it to your channel as admin. Then use @yourchannel as chat_id in your telegram bot for sending messages to your channel. As an example in php:

<?php
$botToken = "yourbottoken";
$chat_id = "@yourchannel";
$message = "your message";
$bot_url    = "https://api.telegram.org/bot$botToken/";
$url = $bot_url."sendMessage?chat_id=".$chat_id."&text=".urlencode($message);
file_get_contents($url);
?>
like image 195
Saeid Tahmuresi Avatar answered Oct 11 '22 06:10

Saeid Tahmuresi