Published: 14 Apr 2021 › Updated: 14 Apr 2021
Pre-format message sending telegram via link
Prequesition:
- Create a Telegram public channel
- Create a Telegram BOT via BotFather
- Set the bot as administrator in your channel
Provided that you did the above, now you can send a message to your channel by issuing an HTTP GET request to the Telegram BOT API at the following URL:
https://api.telegram.org/bot[BOT_API_KEY]/sendMessage?chat_id=[MY_CHANNEL_NAME]&text=[MY_MESSAGE_TEXT]
- BOT_API_KEY is the API Key generated by BotFather when you created your bot
- MY_CHANNEL_NAME is the handle of your channel (e.g. @my_channel_name)
- MY_MESSAGE_TEXT is the message you want to send (URL-encoded)
Now let’s se how to do this in different languages the easy way.
PHP
$apiToken = "my_bot_api_token";
$data = [
'chat_id' => '@my_channel_name',
'text' => 'Hello world!'
];
$response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?" . http_build_query($data) );// Do what you want with result
JAVA
String urlString = "https://api.telegram.org/bot%s/sendMessage?chat_id=%s&text=%s";
String apiToken = "my_bot_api_token";
String chatId = "@my_channel_name";
String text = "Hello world!";
urlString = String.format(urlString, apiToken, chatId, text);
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
StringBuilder sb = new StringBuilder();
InputStream is = new BufferedInputStream(conn.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String inputLine = "";
while ((inputLine = br.readLine()) != null) {
sb.append(inputLine);
}
String response = sb.toString();
// Do what you want with response
Leave Pre-format message sending telegram via link to:
Read more #telegram posts
Best Posts From Faizal Selamat
We have not curated any of onlinedoit's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Faizal Selamat
- Android App For Hive Blog. I thinking of to create android app for d.buzz. What ...
- Pengenalan W-Coin
- Rarely looking moon with star (planet)
- Hello community! I'm wondering where is d.buzz rewards will go? I didn ...
- Pre-format message sending telegram via link
- Bunch of tree at the wall Tree Season![](https://ipfs.io/ipfs/bafybeiakxlgrfycant ...
- Why I can't open d.buzz on laptop? Keep loading..![](https://ipfs.io/i ...
- Sunshine entered restaurant![](https://ipfs.io/ipfs/bafybeicwwuybb5qjc ...
- Monkey everywhere at park![](https://ipfs.io/ipfs/bafybeie2ocsgjuv3ykv ...
- How To Change Cron Job Email Subject
- entah kena delete
- How To Install Free File Manager Version On v=VestaCP