Double bot interface, silent flag
This commit is contained in:
parent
d889e59a31
commit
d0d6964400
|
@ -8,12 +8,16 @@
|
|||
const API_CHANNEL_ID = '@';
|
||||
/* Users whose messages are forwarded to mailing list and channel */
|
||||
const BOT_ALLOWED_USERS = array ();
|
||||
/* Users who can use the new bot interface */
|
||||
const BOT_BETA_TESTERS = array ();
|
||||
/* Address to forward to */
|
||||
const MAIL_TO_ADDR = 'example@example.com';
|
||||
/* Bot email identity */
|
||||
const MAIL_FROM_ADDR = 'example@example.com';
|
||||
/* Debug messages on log file */
|
||||
const DEBUG = true;
|
||||
/* Be silent when forwarding/writing messages to channel */
|
||||
const FORWARD_SILENT = true;
|
||||
/* Log file name */
|
||||
const LOGFILE = 'botlog.log';
|
||||
/* MySQL informations */
|
||||
|
|
23
main.php
23
main.php
|
@ -61,7 +61,7 @@ if (isset ($row->callback_query)) {
|
|||
$chatID = $row->callback_query->message->chat->id;
|
||||
|
||||
// Check if it was thrown by admitted users
|
||||
in_array($row->callback_query->message->chat->username, BOT_ALLOWED_USERS) or not_authorized($chatID);
|
||||
in_array($row->callback_query->message->chat->username, BOT_BETA_TESTERS) or not_authorized($chatID);
|
||||
|
||||
// Answer to the callback query (remove the loading sign)
|
||||
if (DEBUG) info("Callback Query, answering");
|
||||
|
@ -168,7 +168,7 @@ if (isset ($row->callback_query)) {
|
|||
$msg = $mc->get($chatID.MC_FORWARD_MSG)
|
||||
or error("Can't forward message\n");
|
||||
|
||||
forwardMessage(API_CHANNEL_ID, $msg->message->chat->id, $msg->message->message_id, true);
|
||||
forwardMessage(API_CHANNEL_ID, $msg->message->chat->id, $msg->message->message_id, FORWARD_SILENT);
|
||||
|
||||
// Remove kbd
|
||||
$text = "Invio effettuato correttamente";
|
||||
|
@ -256,10 +256,7 @@ if (isset ($row->callback_query)) {
|
|||
}
|
||||
elseif ($callback_data == MSG_ABORT) {
|
||||
$text = "Invio annullato correttamente";
|
||||
$url = API_URL.API_TOKEN."/editMessageText?chat_id=".($chatID).
|
||||
"&message_id=".$inlineID .
|
||||
"&text=".urlencode($text);
|
||||
file_get_contents($url);
|
||||
editMessageText($chatID, $inlineID, $text);
|
||||
$mc->replace($chatID.MC_STATUS, STATE_IDLE) or die();
|
||||
die();
|
||||
}
|
||||
|
@ -330,10 +327,7 @@ if (isset ($row->callback_query)) {
|
|||
$mc->replace($chatID.MC_STATUS, STATE_IDLE);
|
||||
if ($callback_data == MSG_ABORT) {
|
||||
$text = "Invio annullato correttamente";
|
||||
$url = API_URL.API_TOKEN."/editMessageText?chat_id=".($chatID).
|
||||
"&message_id=".$inlineID .
|
||||
"&text=".urlencode($text);
|
||||
file_get_contents($url);
|
||||
editMessageText($chatID, $inlineID, $text);
|
||||
$mc->replace($chatID.MC_STATUS, STATE_IDLE) or die();
|
||||
die();
|
||||
}
|
||||
|
@ -400,7 +394,11 @@ elseif (isset($row->message)) {
|
|||
// Load variables
|
||||
$chatID = $row->message->chat->id;
|
||||
// Check if it was thrown by admitted users
|
||||
in_array($row->message->from->username, BOT_ALLOWED_USERS) or not_authorized($chatID);
|
||||
if (in_array($row->message->from->username, BOT_ALLOWED_USERS)) {
|
||||
info( ' Telegram: forwarding to channel... ');
|
||||
forwardMessage(API_CHANNEL_ID, $row->message->chat->id, $row->message->message_id, FORWARD_SILENT);
|
||||
}
|
||||
else if (in_array($row->message->from->username, BOT_BETA_TESTERS)) {
|
||||
|
||||
// Finally, check actual state and do things
|
||||
$status = $mc->get($chatID.MC_STATUS);
|
||||
|
@ -520,6 +518,9 @@ elseif (isset($row->message)) {
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
not_authorized($chatID);
|
||||
}
|
||||
// a not supported message (i.e. from a channel)
|
||||
else {
|
||||
error("This is not a supported request. Please check JSON dump");
|
||||
|
|
|
@ -27,7 +27,7 @@ while ($row = $query->fetch_assoc()) {
|
|||
"&parse_mode=".urlencode("Markdown");
|
||||
file_get_contents($bot_query);
|
||||
* */
|
||||
forwardMessage(API_CHANNEL_ID, $row['ChatID'], $row['MessageID']) or
|
||||
forwardMessage(API_CHANNEL_ID, $row['ChatID'], $row['MessageID'], FORWARD_SILENT) or
|
||||
error("Scheduler couldn't forward the message. I'll try next hour");
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue