forked from auino/php-telegram-bot-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend.php
56 lines (47 loc) · 1.72 KB
/
send.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
// important: you should secure this page, e.g., through authentication
// call example:
// send.php?chatid=$value&message=Hello%20world!
// see https://github.com/auino/php-telegram-bot-library for more information
// including the library
require("lib/telegram.php");
// if already configured on config.php file, delete/comment following lines
$TELEGRAM_BOTNAME = "samplebot";
$TELEGRAM_TOKEN = "...";
$STATUS_ENABLE = false;
// enable broadcast messages? set to false on non performant hosts
$BROADCASTS_ALLOWED = false;
// checking input parameters
if(!isset($_GET['message'])) exit("Please specify a message to send.");
// getting input parameters
$chatid = null; // send message to all registered chats
if(isset($_GET['chatid'])) $chatid = $_GET['chatid'];
else if(!$BROADCASTS_ALLOWED) exit("Broadcast messages are not allowed");
$message = $_GET['message'];
// checking if logs are enabled (see https://github.com/auino/php-telegram-bot-library for more information)
if(!LOGS_ENABLED) exit("Logs are not enabled for this bot.");
// creating the bot object
$bot = new telegram_bot($TELEGRAM_TOKEN);
try {
// creating base chat list
$chatlist = array();
if($chatid != null) array_push($chatlist, $chatid);
else $chatlist = db_getchatlist($TELEGRAM_BOTNAME);
// iterating over the chat list
foreach($chatlist as $chat) {
// getting current date
$date = (string)time();
// sending the message
$r = $bot->send_message($chat, $message);
// log sent message on the database
@db_log($TELEGRAM_BOTNAME, 'sent', $chat, 'text', $message, $date);
}
// printing output
echo "Message(s) sent!";
}
catch(Exception $e) {
@db_log($TELEGRAM_BOTNAME, 'error', $chatid, 'Error', $date);
// printing the error
echo "Error: $e";
}
?>