forked from piterskiy/etuts-telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend-notify-comment.php
59 lines (46 loc) · 1.95 KB
/
send-notify-comment.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
57
58
59
<?php
require __DIR__.'/vendor/autoload.php';
require_once __DIR__.'/config.php';
use Telegram\Bot\Api;
require __DIR__.'/main-controller.php';
try {
$db = new Database($db_name, $db_user, $db_pass, $chat_id, $message_id);
$telegram = new Api($token);
if (!isset($_POST['author_username']) ||
!isset($_POST['post_title']) ||
!isset($_POST['post_link']) ||
!isset($_POST['comment_content']) ||
!isset($_POST['comment_author']) ||
!isset($_POST['comment_date']) ||
!isset($_POST['comment_id']) ||
empty($_POST))
die;
// content of the message
$author_username = $_POST['author_username'];
$post_title = $_POST['post_title'];
$post_link = $_POST['post_link'];
$comment_content = strip_tags($_POST['comment_content']);
$comment_author = $_POST['comment_author'];
$comment_date = $_POST['comment_date'];
$comment_id = $_POST['comment_id'];
$text = emoji('post_letter_box') . ' شما یک کامنت جدید در مطلب <a href="'.$post_link.'">'.$post_title.'</a> دارید:' . "\n\n" .
emoji('user') . ' نویسنده ی کامنت: ' . $comment_author . "\n" .
emoji('clock') . ' در تاریخ: ' . $comment_date . "\n" .
emoji('blue_diamond') . ' متن کامنت: ' . $comment_content;
// glassy buttons
$approve_btn = create_glassy_btn(emoji('checked') . ' پذیرفتن', 'set_cm_status', ['status' => 'approve']);
$spam_btn = create_glassy_btn(emoji('forbidden') . ' اسپم', 'set_cm_status', ['status' => 'spam']);
$trash_btn = create_glassy_btn(emoji('trash') . ' حذف', 'set_cm_status', ['status' => 'trash']);
$keyboard = create_glassy_keyboard([[$approve_btn, $spam_btn, $trash_btn]]);
$chat_id = $db->get_chat_id_by_etuts_user($author_username);
$telegram->sendMessage([
'chat_id' => $chat_id,
'text' => $text,
'parse_mode' => 'HTML',
'disable_web_page_preview' => true,
'reply_markup' => $keyboard,
]);
log_debug("send-last-rss.php"); //debug
} catch (Exception $e) {
log_debug($e->getPrevious());
}