├── .gitignore
├── src
├── includes
│ ├── extensions.php
│ └── keyboards.php
└── bot.php
├── resources
├── settings.json
└── translations
│ ├── arabic.json
│ ├── persian.json
│ └── english.json
├── composer.json
├── LICENSE
├── README.md
└── composer.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor/
2 | /.vscode/
--------------------------------------------------------------------------------
/src/includes/extensions.php:
--------------------------------------------------------------------------------
1 | message, 'reply_to_message');
7 | });
8 |
--------------------------------------------------------------------------------
/src/includes/keyboards.php:
--------------------------------------------------------------------------------
1 | addCallbackButton($title, "delete_{$chatId}_{$messageId}")
8 | ->get();
9 | }
10 |
--------------------------------------------------------------------------------
/resources/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "bot_token": "BOT_TOKEN",
3 | "owner_id": "0123456789",
4 | "language": "english",
5 | "start_message": "Hi!\nSend your message and wait for my answer.",
6 | "protect_content": false,
7 | "offline_message": "",
8 | "debug_mode": true,
9 | "blocked_users": []
10 | }
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "webpajooh/mediumbot",
3 | "description": "A contact bot to hide your personal account from people",
4 | "type": "project",
5 | "license": "MIT",
6 | "authors": [
7 | {
8 | "name": "WebPajooh",
9 | "email": "webpajooh@gmail.com"
10 | }
11 | ],
12 | "autoload": {
13 | "psr-4": {
14 | "Webpajooh\\Mediumbot\\": "src/"
15 | },
16 | "files": [
17 | "./src/includes/keyboards.php",
18 | "./src/includes/extensions.php"
19 | ]
20 | },
21 | "require": {
22 | "webpajooh/telebot": "^1.3"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/resources/translations/arabic.json:
--------------------------------------------------------------------------------
1 | {
2 | "message_sent": "تم إرسال رسالتك!",
3 | "undo": "❌ إلغاء الإرسال",
4 | "message_deleted": "تم حذف هذه الرسالة!",
5 | "blocked_by_user": "❕ قد قام هذا المستخدم بحظر البوت!",
6 | "user_blocked": "تم حظر هذا المستخدم.",
7 | "user_already_blocked": "❕ ليس المستخدم محظوراً!",
8 | "user_unblocked": "تم إلغاء حظر المستخدم.",
9 | "user_not_blocked": "❕ المستخدم غير محظور!",
10 | "start_message_changed": "من الآن، سيتم عرض هذا النص كرسالة بدء.",
11 | "offline_mode_activated": "تم تنشيط وضع أوفلاين وسيتم عرض هذا النص للمستخدمين.",
12 | "offline_mode_diactivated": "البوت جاهز لاستقبال الرسائل!",
13 | "forward_privacy_error": "⛔️ عذراً، لا يمكن إرسال الرسالة حتى يكون اسمك مكشوفاً؛ راجع:\nSettings > Privacy and Security > Forwarded Messages",
14 | "no_forward": "⛔️ لا يمكنك إرسال رسائل الآخرين للبوت!"
15 | }
--------------------------------------------------------------------------------
/resources/translations/persian.json:
--------------------------------------------------------------------------------
1 | {
2 | "message_sent": "پیام شما ارسال گردید!",
3 | "undo": "❌ حذف",
4 | "message_deleted": "این پیام حذف شده است.",
5 | "blocked_by_user": "❕ این کاربر، ربات را مسدود کرده است!",
6 | "user_blocked": "کاربر مسدود گردید.",
7 | "user_already_blocked": "❕ این کاربر از قبل مسدود شده بود!",
8 | "user_unblocked": "این کاربر دیگر مسدود نیست.",
9 | "user_not_blocked": "❕ این کاربر از قبل مسدود نشده بود!",
10 | "start_message_changed": "از این پس، این پیام به عنوان پیام شروع نمایش داده میشود.",
11 | "offline_mode_activated": "حالت آفلاین فعال و این متن به کاربران نمایش داده خواهد شد.",
12 | "offline_mode_diactivated": "ربات آنلاین است!",
13 | "forward_privacy_error": "⛔️ متأسفم، اما برای ارسال پیام باید در Settings > Privacy and Security > Forwarded Messages حریم خصوصی فوروارد را خاموش کنید.",
14 | "no_forward": "⛔️ شما نمیتوانید پیامی را فوروارد کنید!"
15 | }
--------------------------------------------------------------------------------
/resources/translations/english.json:
--------------------------------------------------------------------------------
1 | {
2 | "message_sent": "Your message has been sent!",
3 | "undo": "❌ Undo",
4 | "message_deleted": "This message was deleted!",
5 | "blocked_by_user": "❕ This user has blocked the bot!",
6 | "user_blocked": "This user is now blocked.",
7 | "user_already_blocked": "❕ This user has already been blocked!",
8 | "user_unblocked": "User unblocked successfully.",
9 | "user_not_blocked": "❕ This user is not blocked!",
10 | "start_message_changed": "From now on, this text will be displayed as start message.",
11 | "offline_mode_activated": "Offline mode is activated and this message will be displayed to users.",
12 | "offline_mode_diactivated": "Bot is online!",
13 | "forward_privacy_error": "⛔️ Sorry, but you must disable your forward privacy in Settings > Privacy and Security > Forwarded Messages before sending messages.",
14 | "no_forward": "⛔️ Forwarding messages is not allowed!"
15 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 WebPajooh
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MediumBot
2 | A contact bot to hide your personal account from people.
3 |
4 | ## Installation
5 | 1. Clone the project:
6 | `git clone https://github.com/WebPajooh/MediumBot`
7 | 2. Edit `resources/settings.json` .
8 | 3. Upload the files to your server and use [setWebhook](https://core.telegram.org/bots/api#setwebhook) to make a connection between your bot and the script. Your URL should be something like this: `https://example.com/some_directory/src/bot.php`.
9 |
10 | That's it! 😌
11 |
12 | ## Settings
13 | | Key | Description | Example |
14 | |--|--|--|
15 | | bot_token | Your token | 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
16 | owner_id | Your ID | 301126514
17 | language | Bot language | english
18 | start_message | The message to show for /start command | Hello!\nHow can I help you?
19 | offline_message | The message to show in offline mode | Sorry... I can't answer your questions now.
20 | protect_content | Protects the contents of the sent message from forwarding and saving | true
21 | debug_mode | Sends error messages | false
22 |
23 | ## Commands
24 |
25 | | Command | Description | Public |
26 | |--|--|--|
27 | | `/start` | Shows a starting message to the user | Yes |
28 | | `!block` | Blocks the user whose message is replied | No |
29 | | `!unblock` | Unblocks the user whose message is replied | No |
30 | | `!setstartmessage` | Updates the starting message to replied message | No |
31 | | `!offline` | Actives offline mode and updates the offline mode message to replied message | No |
32 | | `!online` | Deactivates offline mode and bot will be able to receive messages | No |
33 |
34 | ## Translations
35 | Currently, we support English, Arabic and Persian. The translation files are simple json files located in `resources/translations` directory, containing some strings used by bot. If you needed to customize yours, just edit the language file and upload it to your server.
36 |
37 | ## ⚠️ Issues or Pull Requests
38 | Feel comfortable to report bugs, but we're strict about merging pull requests add new features because we prefer keeping it as simple as possible.
39 |
--------------------------------------------------------------------------------
/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 | "This file is @generated automatically"
6 | ],
7 | "content-hash": "f1001506197c089e5a898f4f35ef319a",
8 | "packages": [
9 | {
10 | "name": "webpajooh/telebot",
11 | "version": "v1.4.0",
12 | "source": {
13 | "type": "git",
14 | "url": "https://github.com/WebPajooh/TeleBot.git",
15 | "reference": "705ea81e9d86cd2494e271c84d21b0d8f4302166"
16 | },
17 | "dist": {
18 | "type": "zip",
19 | "url": "https://api.github.com/repos/WebPajooh/TeleBot/zipball/705ea81e9d86cd2494e271c84d21b0d8f4302166",
20 | "reference": "705ea81e9d86cd2494e271c84d21b0d8f4302166",
21 | "shasum": ""
22 | },
23 | "require": {
24 | "php": ">=7.4"
25 | },
26 | "type": "library",
27 | "autoload": {
28 | "files": [
29 | "src/helpers.php"
30 | ],
31 | "psr-4": {
32 | "TeleBot\\": "src/"
33 | }
34 | },
35 | "notification-url": "https://packagist.org/downloads/",
36 | "license": [
37 | "MIT"
38 | ],
39 | "authors": [
40 | {
41 | "name": "WebPajooh",
42 | "email": "webpajooh@gmail.com"
43 | }
44 | ],
45 | "description": "A minimal tool for Telegram bot developers",
46 | "keywords": [
47 | "telegram",
48 | "telegram bot",
49 | "telegram bot api",
50 | "telegram php",
51 | "telegram sdk"
52 | ],
53 | "support": {
54 | "issues": "https://github.com/WebPajooh/TeleBot/issues",
55 | "source": "https://github.com/WebPajooh/TeleBot/tree/v1.4.0"
56 | },
57 | "time": "2022-06-11T06:15:46+00:00"
58 | }
59 | ],
60 | "packages-dev": [],
61 | "aliases": [],
62 | "minimum-stability": "stable",
63 | "stability-flags": [],
64 | "prefer-stable": false,
65 | "prefer-lowest": false,
66 | "platform": [],
67 | "platform-dev": [],
68 | "plugin-api-version": "2.3.0"
69 | }
70 |
--------------------------------------------------------------------------------
/src/bot.php:
--------------------------------------------------------------------------------
1 | language}.json"));
11 |
12 | $tg = new TeleBot($settings->bot_token);
13 |
14 | if ($settings->offline_message && $tg->user->id != $settings->owner_id) {
15 | return $tg->sendMessage([
16 | 'chat_id' => $tg->user->id,
17 | 'text' => $settings->offline_message,
18 | 'parse_mode' => 'HTML',
19 | ]);
20 | }
21 |
22 | $tg->listen('/start', function () use ($tg, $settings) {
23 | $tg->sendMessage([
24 | 'chat_id' => $tg->user->id,
25 | 'text' => $settings->start_message,
26 | 'parse_mode' => 'HTML',
27 | ]);
28 | });
29 |
30 | $tg->listen('delete_%d_%d', function ($chatId, $messageId) use ($tg, $settings, $strings) {
31 | if ($tg->user->id != $settings->owner_id) {
32 | return;
33 | }
34 |
35 | $result = $tg->deleteMessage([
36 | 'chat_id' => $chatId,
37 | 'message_id' => $messageId,
38 | ]);
39 |
40 | if ($result) {
41 | $tg->editMessageText([
42 | 'chat_id' => $tg->user->id,
43 | 'message_id' => $tg->message->message_id,
44 | 'text' => $strings->message_deleted,
45 | ]);
46 | }
47 | });
48 |
49 | $tg->listen('!block', function () use ($tg, $settings, $strings) {
50 | if ($tg->user->id != $settings->owner_id) {
51 | return;
52 | }
53 |
54 | if (! $tg->isReply()) {
55 | return;
56 | }
57 |
58 | if (! property_exists($tg->message->reply_to_message, 'forward_from')) {
59 | die;
60 | }
61 |
62 | $userId = $tg->message->reply_to_message->forward_from->id;
63 |
64 | if (in_array($userId, $settings->blocked_users)) {
65 | $tg->sendMessage([
66 | 'chat_id' => $settings->owner_id,
67 | 'reply_to_message_id' => $tg->message->message_id,
68 | 'text' => $strings->user_already_blocked,
69 | ]);
70 | } else {
71 | $settings->blocked_users[] = $userId;
72 | file_put_contents('../resources/settings.json', json_encode($settings));
73 |
74 | $tg->sendMessage([
75 | 'chat_id' => $settings->owner_id,
76 | 'reply_to_message_id' => $tg->message->message_id,
77 | 'text' => $strings->user_blocked,
78 | ]);
79 | }
80 | });
81 |
82 | $tg->listen('!unblock', function () use ($tg, $settings, $strings) {
83 | if ($tg->user->id != $settings->owner_id) {
84 | return;
85 | }
86 |
87 | if (! $tg->isReply()) {
88 | return;
89 | }
90 |
91 | if (! property_exists($tg->message->reply_to_message, 'forward_from')) {
92 | die;
93 | }
94 |
95 | $userId = $tg->message->reply_to_message->forward_from->id;
96 |
97 | if (in_array($userId, $settings->blocked_users)) {
98 | array_splice($settings->blocked_users, array_search($userId, $settings->blocked_users));
99 | file_put_contents('../resources/settings.json', json_encode($settings));
100 |
101 | $tg->sendMessage([
102 | 'chat_id' => $settings->owner_id,
103 | 'reply_to_message_id' => $tg->message->message_id,
104 | 'text' => $strings->user_unblocked,
105 | ]);
106 | } else {
107 | $tg->sendMessage([
108 | 'chat_id' => $settings->owner_id,
109 | 'reply_to_message_id' => $tg->message->message_id,
110 | 'text' => $strings->user_not_blocked,
111 | ]);
112 | }
113 | });
114 |
115 | $tg->listen('!setstartmessage', function () use ($tg, $settings, $strings) {
116 | if ($tg->user->id != $settings->owner_id) {
117 | return;
118 | }
119 |
120 | if (! $tg->isReply()) {
121 | return;
122 | }
123 |
124 | if (! $tg->message->reply_to_message->text) {
125 | return;
126 | }
127 |
128 | $settings->start_message = $tg->message->reply_to_message->text;
129 | file_put_contents('../resources/settings.json', json_encode($settings));
130 |
131 | $tg->sendMessage([
132 | 'chat_id' => $settings->owner_id,
133 | 'reply_to_message_id' => $tg->message->reply_to_message->message_id,
134 | 'text' => $strings->start_message_changed,
135 | ]);
136 | });
137 |
138 | $tg->listen('!offline', function () use ($tg, $settings, $strings) {
139 | if ($tg->user->id != $settings->owner_id) {
140 | return;
141 | }
142 |
143 | if (! $tg->isReply()) {
144 | return;
145 | }
146 |
147 | if (! $tg->message->reply_to_message->text) {
148 | return;
149 | }
150 |
151 | $settings->offline_message = $tg->message->reply_to_message->text;
152 | file_put_contents('../resources/settings.json', json_encode($settings));
153 |
154 | $tg->sendMessage([
155 | 'chat_id' => $settings->owner_id,
156 | 'reply_to_message_id' => $tg->message->reply_to_message->message_id,
157 | 'text' => $strings->offline_mode_activated,
158 | ]);
159 | });
160 |
161 | $tg->listen('!online', function () use ($tg, $settings, $strings) {
162 | if ($tg->user->id != $settings->owner_id) {
163 | return;
164 | }
165 |
166 | $settings->offline_message = "";
167 | file_put_contents('../resources/settings.json', json_encode($settings));
168 |
169 | $tg->sendMessage([
170 | 'chat_id' => $settings->owner_id,
171 | 'reply_to_message_id' => $tg->message->reply_to_message->message_id,
172 | 'text' => $strings->offline_mode_diactivated,
173 | ]);
174 | });
175 |
176 | if ($tg->user->id == $settings->owner_id) {
177 | if (! $tg->isReply()) {
178 | die;
179 | }
180 |
181 | if (! property_exists($tg->message->reply_to_message, 'forward_from')) {
182 | die;
183 | }
184 |
185 | try {
186 | $messageId = $tg->copyMessage([
187 | 'from_chat_id' => $settings->owner_id,
188 | 'chat_id' => $tg->message->reply_to_message->forward_from->id,
189 | 'message_id' => $tg->message->message_id,
190 | 'protect_content' => $settings->protect_content,
191 | ]);
192 | } catch (TeleBotException $e) {
193 | if ($e->getMessage() == 'Forbidden: bot was blocked by the user') {
194 | $tg->sendMessage([
195 | 'chat_id' => $settings->owner_id,
196 | 'reply_to_message_id' => $tg->message->message_id,
197 | 'text' => $strings->blocked_by_user,
198 | ]);
199 |
200 | die;
201 | }
202 | }
203 |
204 | if (property_exists($messageId, 'message_id')) {
205 | $tg->sendMessage([
206 | 'chat_id' => $settings->owner_id,
207 | 'reply_to_message_id' => $tg->message->message_id,
208 | 'text' => $strings->message_sent,
209 | 'reply_markup' => getUndoKeyboard($strings->undo, $tg->message->reply_to_message->forward_from->id, $messageId->message_id),
210 | ]);
211 | }
212 | } else {
213 | if (in_array($tg->user->id, $settings->blocked_users)) {
214 | die;
215 | }
216 |
217 | if (property_exists($tg->message, 'forward_date')) {
218 | $tg->sendMessage([
219 | 'chat_id' => $tg->user->id,
220 | 'reply_to_message_id' => $tg->message->message_id,
221 | 'text' => $strings->no_forward,
222 | ]);
223 |
224 | die;
225 | }
226 |
227 | $forwardedMessage = $tg->forwardMessage([
228 | 'from_chat_id' => $tg->user->id,
229 | 'chat_id' => $settings->owner_id,
230 | 'message_id' => $tg->message->message_id,
231 | ]);
232 |
233 | if (property_exists($forwardedMessage, 'forward_sender_name')) {
234 | $tg->deleteMessage([
235 | 'chat_id' => $settings->owner_id,
236 | 'message_id' => $forwardedMessage->message_id,
237 | ]);
238 |
239 | $tg->sendMessage([
240 | 'chat_id' => $tg->user->id,
241 | 'reply_to_message_id' => $tg->message->message_id,
242 | 'text' => $strings->forward_privacy_error,
243 | 'parse_mode' => 'HTML',
244 | ]);
245 | }
246 | }
247 | } catch (Throwable $th) {
248 | if ($settings->debug_mode) {
249 | $command = $tg->hasCallbackQuery() ?
250 | $tg->update->callback_query->data :
251 | $tg->update->message->text;
252 |
253 | $text = "‼️ Something went wrong\n\n";
254 | $text .= "💬 Command: {$command}\n";
255 | $text .= "🔻 Message: {$th->getMessage()}\n";
256 | $text .= "📃 File: {$th->getFile()}\n";
257 | $text .= "⤵️ Line: {$th->getLine()}";
258 |
259 | $tg->sendMessage([
260 | 'chat_id' => $settings->owner_id,
261 | 'text' => $text,
262 | 'parse_mode' => 'html',
263 | ]);
264 | }
265 | }
266 |
--------------------------------------------------------------------------------