├── .gitignore
├── LICENSE
├── README.md
├── app.json
├── composer.json
├── composer.lock
├── config
├── config.php
└── functions.php
├── img
└── github.jpeg
├── index.php
├── setWebhook.php
└── src
└── GitHubBot.php
/.gitignore:
--------------------------------------------------------------------------------
1 | /.idea
2 | /vendor
3 | /node_modules
4 | /logs
5 | /tests
6 | /.env.local
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Albin Varghese
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 |
Github Telegram Bot
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | Github Telegram Bot is a php bot for notifying Events from your github repository.
11 |
12 | ## Table of Contents
13 |
14 | - [Introduction](#introduction)
15 | - [Features](#features)
16 | - [Screenshots](#screenshots)
17 | - [Installation](#installation-heroku)
18 | - [Contributing](#contributing)
19 | - [License](#license)
20 |
21 | ## Introduction
22 |
23 | This is the introduction section and a brief description is provided within this section.
24 |
25 | ## Features
26 |
27 | Get Instant Notifications for
28 |
29 | - Pushes
30 | - Pull Request(open)
31 | - Comment
32 | - Issue(open)
33 | - Issue(close)
34 | - Merge
35 |
36 | ### Create a New Bot
37 | 1. Add [@BotFather](https://telegram.me/botfather) to start conversation.
38 | 2. Type `/newbot` and **@BotFather** will ask the name for your bot.
39 | 3. Choose a cool name, for example `My Github Bot` and hit enter.
40 | 4. Now choose a username for your bot. It must end in *bot*, for example `GithubBot` or `Github_Bot`.
41 | 5. If succeed, **@BotFather** will give you API key to be used in this bot.
42 |
43 | ## Screenshots
44 |
45 |
46 |
47 |
48 | ## Installation (Heroku)
49 |
50 |
51 | 0. Create a Account on [Heroku](https://heroku.com)
52 |
53 | 1. Click `Create New App` in Heroku Dashboard
54 |
55 | 2. Enter App Name and click on create app
56 |
57 | 3. Now install Heroku CLI on your Computer [Instuctions](https://devcenter.heroku.com/articles/heroku-cli)
58 |
59 | 4. Now open your terminal and run command `git clone https://github.com/albinvar/Github-Telegram-Bot.git`
60 |
61 | 5. It will download Latest codes for you in your Device
62 |
63 | 6. Now change the directory to test using command `cd test`
64 |
65 | 7. Now Login into Heroku CLI using command `heroku login -i` now enter your login details and hit Enter
66 |
67 | 8. After Login run this command in terminal `heroku git:remote -a appName` here appName will be your app's name that you choose while creating the app.
68 |
69 | 9. Now run follow commands in termial to install packages `heroku buildpacks:add heroku/php`
70 |
71 | 10. Now run this command in your terminal `git push heroku master`, if this gives an error try this `git push -f heroku master`
72 |
73 | 11. All done now it will take time to complete, after that you can visit your domain shown in terminal.
74 |
75 | ## Installation on Heroku (Easy way)
76 | Easily deploy using the button below
77 |
78 | [](https://heroku.com/deploy)
79 |
80 | ## Installation (VPS/Localhost)
81 |
82 | 1. Clone the repository using git. `git clone https://github.com/albinvar/Github-Telegram-Bot.git`
83 |
84 | 2. Install all pacakges using composer. `composer install`
85 |
86 | 3. Now change your directory using `cd Github-Telegram-Bot`
87 |
88 | 4. Start a localhost using `php -S localhost:8080`
89 |
90 | 5. You can setup your port-forwarding method. (Services like ngrok, serveo.net)
91 |
92 | ## Setup Port-forwarding
93 |
94 | 1. Install and Configure ngrok on your localmachine.
95 |
96 | 2. Start Port-forwarding using the command `ngrok http 8080`
97 |
98 | 3. Set the link with https as webhook using setWebhook.php
99 |
100 | 4. You are good to go...
101 |
102 | ## Set Webhook
103 |
104 | 1. Open `http://YOUR_DOMAIN.COM/setWebhook.php` on your server/localhost.
105 |
106 | 2. It will set your webhook based on the current server address for receiving calls from Telegram API.
107 |
108 | 3. If you get a message saying "webhook set successfully". You are good to go....
109 |
110 | ## Set webhook on Github
111 |
112 | 1. Choose a repository on Github which you want to receive notifications.
113 |
114 | 2. Direct to repo-settings->webhooks->add webhook
115 |
116 | 3. Set the payload url ngrok/website link.
117 |
118 | 4. Select `application/x-www-form-urlencoded` and select `All Events`
119 |
120 | 5. Hit Enter and you will get all notifications from your Telegram bot
121 |
122 | ```Note that : Your ngrok link will expire after sometimes. Using webhosting/vps is suggested```
123 |
124 | ## Contributing
125 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
126 |
127 | ## License
128 | This project is certified using [MIT License](https://github.com/albinvar/Github-Telegram-Bot/blob/main/LICENSE)
129 |
--------------------------------------------------------------------------------
/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Github Telegram Bot",
3 | "description": "Telegram bot designed to deliver notifications from your Github Repository built using php",
4 | "keywords": [
5 | "github",
6 | "notifications",
7 | "telegram"
8 | ],
9 | "website": "https://github-telegram-bot.surge.sh",
10 | "repository": "https://github.com/albinvar/Github-Telegram-Bot",
11 | "success_url": "/setWebhook.php",
12 | "env": {
13 | "BOT_TOKEN": {
14 | "description": "Your Telegram Bot Token, from @BotFather"
15 | },
16 | "ADMINS": {
17 | "description": "A space separated list of user IDs who you want to assign as admin users."
18 | }
19 | },
20 | "formation": {
21 | "web": {
22 | "quantity": 1,
23 | "size": "free"
24 | }
25 | },
26 | "image": "heroku/php"
27 | }
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "require": {
3 | "ext-json": "*",
4 | "eleirbag89/telegrambotphp": "^1.3",
5 | "guzzlehttp/guzzle": "^7.2",
6 | "symfony/http-foundation": "^5.1"
7 | },
8 | "config": {
9 | "optimize-autoloader": true,
10 | "sort-packages": true
11 | },
12 | "autoload": {
13 | "psr-4": {
14 | "App\\": "src/"
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/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": "2f0e89babcefd322a40b5925bce6afcb",
8 | "packages": [
9 | {
10 | "name": "eleirbag89/telegrambotphp",
11 | "version": "1.3.11",
12 | "source": {
13 | "type": "git",
14 | "url": "https://github.com/Eleirbag89/TelegramBotPHP.git",
15 | "reference": "d5464bc7356f6031991e636b6b1b2402cbae88ea"
16 | },
17 | "dist": {
18 | "type": "zip",
19 | "url": "https://api.github.com/repos/Eleirbag89/TelegramBotPHP/zipball/d5464bc7356f6031991e636b6b1b2402cbae88ea",
20 | "reference": "d5464bc7356f6031991e636b6b1b2402cbae88ea",
21 | "shasum": ""
22 | },
23 | "require": {
24 | "ext-curl": "*",
25 | "ext-json": "*",
26 | "php": ">=5.0"
27 | },
28 | "type": "library",
29 | "autoload": {
30 | "files": [
31 | "Telegram.php",
32 | "TelegramErrorLogger.php"
33 | ]
34 | },
35 | "notification-url": "https://packagist.org/downloads/",
36 | "license": [
37 | "MIT"
38 | ],
39 | "authors": [
40 | {
41 | "name": "Gabriele Grillo",
42 | "email": "gabry.grillo@alice.it"
43 | }
44 | ],
45 | "description": "A very simple PHP Telegram Bot API",
46 | "support": {
47 | "issues": "https://github.com/Eleirbag89/TelegramBotPHP/issues",
48 | "source": "https://github.com/Eleirbag89/TelegramBotPHP/tree/1.3.11"
49 | },
50 | "funding": [
51 | {
52 | "url": "https://flattr.com/@Eleirbag89",
53 | "type": "custom"
54 | },
55 | {
56 | "url": "https://paypal.me/eleirbag89",
57 | "type": "custom"
58 | },
59 | {
60 | "url": "https://liberapay.com/eleirbag89",
61 | "type": "liberapay"
62 | }
63 | ],
64 | "time": "2020-06-24T16:20:03+00:00"
65 | },
66 | {
67 | "name": "guzzlehttp/guzzle",
68 | "version": "7.2.0",
69 | "source": {
70 | "type": "git",
71 | "url": "https://github.com/guzzle/guzzle.git",
72 | "reference": "0aa74dfb41ae110835923ef10a9d803a22d50e79"
73 | },
74 | "dist": {
75 | "type": "zip",
76 | "url": "https://api.github.com/repos/guzzle/guzzle/zipball/0aa74dfb41ae110835923ef10a9d803a22d50e79",
77 | "reference": "0aa74dfb41ae110835923ef10a9d803a22d50e79",
78 | "shasum": ""
79 | },
80 | "require": {
81 | "ext-json": "*",
82 | "guzzlehttp/promises": "^1.4",
83 | "guzzlehttp/psr7": "^1.7",
84 | "php": "^7.2.5 || ^8.0",
85 | "psr/http-client": "^1.0"
86 | },
87 | "provide": {
88 | "psr/http-client-implementation": "1.0"
89 | },
90 | "require-dev": {
91 | "ext-curl": "*",
92 | "php-http/client-integration-tests": "^3.0",
93 | "phpunit/phpunit": "^8.5.5 || ^9.3.5",
94 | "psr/log": "^1.1"
95 | },
96 | "suggest": {
97 | "ext-curl": "Required for CURL handler support",
98 | "ext-intl": "Required for Internationalized Domain Name (IDN) support",
99 | "psr/log": "Required for using the Log middleware"
100 | },
101 | "type": "library",
102 | "extra": {
103 | "branch-alias": {
104 | "dev-master": "7.1-dev"
105 | }
106 | },
107 | "autoload": {
108 | "psr-4": {
109 | "GuzzleHttp\\": "src/"
110 | },
111 | "files": [
112 | "src/functions_include.php"
113 | ]
114 | },
115 | "notification-url": "https://packagist.org/downloads/",
116 | "license": [
117 | "MIT"
118 | ],
119 | "authors": [
120 | {
121 | "name": "Michael Dowling",
122 | "email": "mtdowling@gmail.com",
123 | "homepage": "https://github.com/mtdowling"
124 | },
125 | {
126 | "name": "Márk Sági-Kazár",
127 | "email": "mark.sagikazar@gmail.com",
128 | "homepage": "https://sagikazarmark.hu"
129 | }
130 | ],
131 | "description": "Guzzle is a PHP HTTP client library",
132 | "homepage": "http://guzzlephp.org/",
133 | "keywords": [
134 | "client",
135 | "curl",
136 | "framework",
137 | "http",
138 | "http client",
139 | "psr-18",
140 | "psr-7",
141 | "rest",
142 | "web service"
143 | ],
144 | "support": {
145 | "issues": "https://github.com/guzzle/guzzle/issues",
146 | "source": "https://github.com/guzzle/guzzle/tree/7.2.0"
147 | },
148 | "funding": [
149 | {
150 | "url": "https://github.com/GrahamCampbell",
151 | "type": "github"
152 | },
153 | {
154 | "url": "https://github.com/Nyholm",
155 | "type": "github"
156 | },
157 | {
158 | "url": "https://github.com/alexeyshockov",
159 | "type": "github"
160 | },
161 | {
162 | "url": "https://github.com/gmponos",
163 | "type": "github"
164 | }
165 | ],
166 | "time": "2020-10-10T11:47:56+00:00"
167 | },
168 | {
169 | "name": "guzzlehttp/promises",
170 | "version": "1.4.0",
171 | "source": {
172 | "type": "git",
173 | "url": "https://github.com/guzzle/promises.git",
174 | "reference": "60d379c243457e073cff02bc323a2a86cb355631"
175 | },
176 | "dist": {
177 | "type": "zip",
178 | "url": "https://api.github.com/repos/guzzle/promises/zipball/60d379c243457e073cff02bc323a2a86cb355631",
179 | "reference": "60d379c243457e073cff02bc323a2a86cb355631",
180 | "shasum": ""
181 | },
182 | "require": {
183 | "php": ">=5.5"
184 | },
185 | "require-dev": {
186 | "symfony/phpunit-bridge": "^4.4 || ^5.1"
187 | },
188 | "type": "library",
189 | "extra": {
190 | "branch-alias": {
191 | "dev-master": "1.4-dev"
192 | }
193 | },
194 | "autoload": {
195 | "psr-4": {
196 | "GuzzleHttp\\Promise\\": "src/"
197 | },
198 | "files": [
199 | "src/functions_include.php"
200 | ]
201 | },
202 | "notification-url": "https://packagist.org/downloads/",
203 | "license": [
204 | "MIT"
205 | ],
206 | "authors": [
207 | {
208 | "name": "Michael Dowling",
209 | "email": "mtdowling@gmail.com",
210 | "homepage": "https://github.com/mtdowling"
211 | }
212 | ],
213 | "description": "Guzzle promises library",
214 | "keywords": [
215 | "promise"
216 | ],
217 | "support": {
218 | "issues": "https://github.com/guzzle/promises/issues",
219 | "source": "https://github.com/guzzle/promises/tree/1.4.0"
220 | },
221 | "time": "2020-09-30T07:37:28+00:00"
222 | },
223 | {
224 | "name": "guzzlehttp/psr7",
225 | "version": "1.7.0",
226 | "source": {
227 | "type": "git",
228 | "url": "https://github.com/guzzle/psr7.git",
229 | "reference": "53330f47520498c0ae1f61f7e2c90f55690c06a3"
230 | },
231 | "dist": {
232 | "type": "zip",
233 | "url": "https://api.github.com/repos/guzzle/psr7/zipball/53330f47520498c0ae1f61f7e2c90f55690c06a3",
234 | "reference": "53330f47520498c0ae1f61f7e2c90f55690c06a3",
235 | "shasum": ""
236 | },
237 | "require": {
238 | "php": ">=5.4.0",
239 | "psr/http-message": "~1.0",
240 | "ralouphie/getallheaders": "^2.0.5 || ^3.0.0"
241 | },
242 | "provide": {
243 | "psr/http-message-implementation": "1.0"
244 | },
245 | "require-dev": {
246 | "ext-zlib": "*",
247 | "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.10"
248 | },
249 | "suggest": {
250 | "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses"
251 | },
252 | "type": "library",
253 | "extra": {
254 | "branch-alias": {
255 | "dev-master": "1.7-dev"
256 | }
257 | },
258 | "autoload": {
259 | "psr-4": {
260 | "GuzzleHttp\\Psr7\\": "src/"
261 | },
262 | "files": [
263 | "src/functions_include.php"
264 | ]
265 | },
266 | "notification-url": "https://packagist.org/downloads/",
267 | "license": [
268 | "MIT"
269 | ],
270 | "authors": [
271 | {
272 | "name": "Michael Dowling",
273 | "email": "mtdowling@gmail.com",
274 | "homepage": "https://github.com/mtdowling"
275 | },
276 | {
277 | "name": "Tobias Schultze",
278 | "homepage": "https://github.com/Tobion"
279 | }
280 | ],
281 | "description": "PSR-7 message implementation that also provides common utility methods",
282 | "keywords": [
283 | "http",
284 | "message",
285 | "psr-7",
286 | "request",
287 | "response",
288 | "stream",
289 | "uri",
290 | "url"
291 | ],
292 | "support": {
293 | "issues": "https://github.com/guzzle/psr7/issues",
294 | "source": "https://github.com/guzzle/psr7/tree/1.7.0"
295 | },
296 | "time": "2020-09-30T07:37:11+00:00"
297 | },
298 | {
299 | "name": "psr/http-client",
300 | "version": "1.0.1",
301 | "source": {
302 | "type": "git",
303 | "url": "https://github.com/php-fig/http-client.git",
304 | "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621"
305 | },
306 | "dist": {
307 | "type": "zip",
308 | "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621",
309 | "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621",
310 | "shasum": ""
311 | },
312 | "require": {
313 | "php": "^7.0 || ^8.0",
314 | "psr/http-message": "^1.0"
315 | },
316 | "type": "library",
317 | "extra": {
318 | "branch-alias": {
319 | "dev-master": "1.0.x-dev"
320 | }
321 | },
322 | "autoload": {
323 | "psr-4": {
324 | "Psr\\Http\\Client\\": "src/"
325 | }
326 | },
327 | "notification-url": "https://packagist.org/downloads/",
328 | "license": [
329 | "MIT"
330 | ],
331 | "authors": [
332 | {
333 | "name": "PHP-FIG",
334 | "homepage": "http://www.php-fig.org/"
335 | }
336 | ],
337 | "description": "Common interface for HTTP clients",
338 | "homepage": "https://github.com/php-fig/http-client",
339 | "keywords": [
340 | "http",
341 | "http-client",
342 | "psr",
343 | "psr-18"
344 | ],
345 | "support": {
346 | "source": "https://github.com/php-fig/http-client/tree/master"
347 | },
348 | "time": "2020-06-29T06:28:15+00:00"
349 | },
350 | {
351 | "name": "psr/http-message",
352 | "version": "1.0.1",
353 | "source": {
354 | "type": "git",
355 | "url": "https://github.com/php-fig/http-message.git",
356 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
357 | },
358 | "dist": {
359 | "type": "zip",
360 | "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
361 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
362 | "shasum": ""
363 | },
364 | "require": {
365 | "php": ">=5.3.0"
366 | },
367 | "type": "library",
368 | "extra": {
369 | "branch-alias": {
370 | "dev-master": "1.0.x-dev"
371 | }
372 | },
373 | "autoload": {
374 | "psr-4": {
375 | "Psr\\Http\\Message\\": "src/"
376 | }
377 | },
378 | "notification-url": "https://packagist.org/downloads/",
379 | "license": [
380 | "MIT"
381 | ],
382 | "authors": [
383 | {
384 | "name": "PHP-FIG",
385 | "homepage": "http://www.php-fig.org/"
386 | }
387 | ],
388 | "description": "Common interface for HTTP messages",
389 | "homepage": "https://github.com/php-fig/http-message",
390 | "keywords": [
391 | "http",
392 | "http-message",
393 | "psr",
394 | "psr-7",
395 | "request",
396 | "response"
397 | ],
398 | "support": {
399 | "source": "https://github.com/php-fig/http-message/tree/master"
400 | },
401 | "time": "2016-08-06T14:39:51+00:00"
402 | },
403 | {
404 | "name": "ralouphie/getallheaders",
405 | "version": "3.0.3",
406 | "source": {
407 | "type": "git",
408 | "url": "https://github.com/ralouphie/getallheaders.git",
409 | "reference": "120b605dfeb996808c31b6477290a714d356e822"
410 | },
411 | "dist": {
412 | "type": "zip",
413 | "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822",
414 | "reference": "120b605dfeb996808c31b6477290a714d356e822",
415 | "shasum": ""
416 | },
417 | "require": {
418 | "php": ">=5.6"
419 | },
420 | "require-dev": {
421 | "php-coveralls/php-coveralls": "^2.1",
422 | "phpunit/phpunit": "^5 || ^6.5"
423 | },
424 | "type": "library",
425 | "autoload": {
426 | "files": [
427 | "src/getallheaders.php"
428 | ]
429 | },
430 | "notification-url": "https://packagist.org/downloads/",
431 | "license": [
432 | "MIT"
433 | ],
434 | "authors": [
435 | {
436 | "name": "Ralph Khattar",
437 | "email": "ralph.khattar@gmail.com"
438 | }
439 | ],
440 | "description": "A polyfill for getallheaders.",
441 | "support": {
442 | "issues": "https://github.com/ralouphie/getallheaders/issues",
443 | "source": "https://github.com/ralouphie/getallheaders/tree/develop"
444 | },
445 | "time": "2019-03-08T08:55:37+00:00"
446 | },
447 | {
448 | "name": "symfony/deprecation-contracts",
449 | "version": "v2.2.0",
450 | "source": {
451 | "type": "git",
452 | "url": "https://github.com/symfony/deprecation-contracts.git",
453 | "reference": "5fa56b4074d1ae755beb55617ddafe6f5d78f665"
454 | },
455 | "dist": {
456 | "type": "zip",
457 | "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/5fa56b4074d1ae755beb55617ddafe6f5d78f665",
458 | "reference": "5fa56b4074d1ae755beb55617ddafe6f5d78f665",
459 | "shasum": ""
460 | },
461 | "require": {
462 | "php": ">=7.1"
463 | },
464 | "type": "library",
465 | "extra": {
466 | "branch-alias": {
467 | "dev-master": "2.2-dev"
468 | },
469 | "thanks": {
470 | "name": "symfony/contracts",
471 | "url": "https://github.com/symfony/contracts"
472 | }
473 | },
474 | "autoload": {
475 | "files": [
476 | "function.php"
477 | ]
478 | },
479 | "notification-url": "https://packagist.org/downloads/",
480 | "license": [
481 | "MIT"
482 | ],
483 | "authors": [
484 | {
485 | "name": "Nicolas Grekas",
486 | "email": "p@tchwork.com"
487 | },
488 | {
489 | "name": "Symfony Community",
490 | "homepage": "https://symfony.com/contributors"
491 | }
492 | ],
493 | "description": "A generic function and convention to trigger deprecation notices",
494 | "homepage": "https://symfony.com",
495 | "support": {
496 | "source": "https://github.com/symfony/deprecation-contracts/tree/master"
497 | },
498 | "funding": [
499 | {
500 | "url": "https://symfony.com/sponsor",
501 | "type": "custom"
502 | },
503 | {
504 | "url": "https://github.com/fabpot",
505 | "type": "github"
506 | },
507 | {
508 | "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
509 | "type": "tidelift"
510 | }
511 | ],
512 | "time": "2020-09-07T11:33:47+00:00"
513 | },
514 | {
515 | "name": "symfony/http-foundation",
516 | "version": "v5.2.1",
517 | "source": {
518 | "type": "git",
519 | "url": "https://github.com/symfony/http-foundation.git",
520 | "reference": "a1f6218b29897ab52acba58cfa905b83625bef8d"
521 | },
522 | "dist": {
523 | "type": "zip",
524 | "url": "https://api.github.com/repos/symfony/http-foundation/zipball/a1f6218b29897ab52acba58cfa905b83625bef8d",
525 | "reference": "a1f6218b29897ab52acba58cfa905b83625bef8d",
526 | "shasum": ""
527 | },
528 | "require": {
529 | "php": ">=7.2.5",
530 | "symfony/deprecation-contracts": "^2.1",
531 | "symfony/polyfill-mbstring": "~1.1",
532 | "symfony/polyfill-php80": "^1.15"
533 | },
534 | "require-dev": {
535 | "predis/predis": "~1.0",
536 | "symfony/cache": "^4.4|^5.0",
537 | "symfony/expression-language": "^4.4|^5.0",
538 | "symfony/mime": "^4.4|^5.0"
539 | },
540 | "suggest": {
541 | "symfony/mime": "To use the file extension guesser"
542 | },
543 | "type": "library",
544 | "autoload": {
545 | "psr-4": {
546 | "Symfony\\Component\\HttpFoundation\\": ""
547 | },
548 | "exclude-from-classmap": [
549 | "/Tests/"
550 | ]
551 | },
552 | "notification-url": "https://packagist.org/downloads/",
553 | "license": [
554 | "MIT"
555 | ],
556 | "authors": [
557 | {
558 | "name": "Fabien Potencier",
559 | "email": "fabien@symfony.com"
560 | },
561 | {
562 | "name": "Symfony Community",
563 | "homepage": "https://symfony.com/contributors"
564 | }
565 | ],
566 | "description": "Symfony HttpFoundation Component",
567 | "homepage": "https://symfony.com",
568 | "support": {
569 | "source": "https://github.com/symfony/http-foundation/tree/v5.2.1"
570 | },
571 | "funding": [
572 | {
573 | "url": "https://symfony.com/sponsor",
574 | "type": "custom"
575 | },
576 | {
577 | "url": "https://github.com/fabpot",
578 | "type": "github"
579 | },
580 | {
581 | "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
582 | "type": "tidelift"
583 | }
584 | ],
585 | "time": "2020-12-18T10:00:10+00:00"
586 | },
587 | {
588 | "name": "symfony/polyfill-mbstring",
589 | "version": "v1.20.0",
590 | "source": {
591 | "type": "git",
592 | "url": "https://github.com/symfony/polyfill-mbstring.git",
593 | "reference": "39d483bdf39be819deabf04ec872eb0b2410b531"
594 | },
595 | "dist": {
596 | "type": "zip",
597 | "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/39d483bdf39be819deabf04ec872eb0b2410b531",
598 | "reference": "39d483bdf39be819deabf04ec872eb0b2410b531",
599 | "shasum": ""
600 | },
601 | "require": {
602 | "php": ">=7.1"
603 | },
604 | "suggest": {
605 | "ext-mbstring": "For best performance"
606 | },
607 | "type": "library",
608 | "extra": {
609 | "branch-alias": {
610 | "dev-main": "1.20-dev"
611 | },
612 | "thanks": {
613 | "name": "symfony/polyfill",
614 | "url": "https://github.com/symfony/polyfill"
615 | }
616 | },
617 | "autoload": {
618 | "psr-4": {
619 | "Symfony\\Polyfill\\Mbstring\\": ""
620 | },
621 | "files": [
622 | "bootstrap.php"
623 | ]
624 | },
625 | "notification-url": "https://packagist.org/downloads/",
626 | "license": [
627 | "MIT"
628 | ],
629 | "authors": [
630 | {
631 | "name": "Nicolas Grekas",
632 | "email": "p@tchwork.com"
633 | },
634 | {
635 | "name": "Symfony Community",
636 | "homepage": "https://symfony.com/contributors"
637 | }
638 | ],
639 | "description": "Symfony polyfill for the Mbstring extension",
640 | "homepage": "https://symfony.com",
641 | "keywords": [
642 | "compatibility",
643 | "mbstring",
644 | "polyfill",
645 | "portable",
646 | "shim"
647 | ],
648 | "support": {
649 | "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.20.0"
650 | },
651 | "funding": [
652 | {
653 | "url": "https://symfony.com/sponsor",
654 | "type": "custom"
655 | },
656 | {
657 | "url": "https://github.com/fabpot",
658 | "type": "github"
659 | },
660 | {
661 | "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
662 | "type": "tidelift"
663 | }
664 | ],
665 | "time": "2020-10-23T14:02:19+00:00"
666 | },
667 | {
668 | "name": "symfony/polyfill-php80",
669 | "version": "v1.20.0",
670 | "source": {
671 | "type": "git",
672 | "url": "https://github.com/symfony/polyfill-php80.git",
673 | "reference": "e70aa8b064c5b72d3df2abd5ab1e90464ad009de"
674 | },
675 | "dist": {
676 | "type": "zip",
677 | "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/e70aa8b064c5b72d3df2abd5ab1e90464ad009de",
678 | "reference": "e70aa8b064c5b72d3df2abd5ab1e90464ad009de",
679 | "shasum": ""
680 | },
681 | "require": {
682 | "php": ">=7.1"
683 | },
684 | "type": "library",
685 | "extra": {
686 | "branch-alias": {
687 | "dev-main": "1.20-dev"
688 | },
689 | "thanks": {
690 | "name": "symfony/polyfill",
691 | "url": "https://github.com/symfony/polyfill"
692 | }
693 | },
694 | "autoload": {
695 | "psr-4": {
696 | "Symfony\\Polyfill\\Php80\\": ""
697 | },
698 | "files": [
699 | "bootstrap.php"
700 | ],
701 | "classmap": [
702 | "Resources/stubs"
703 | ]
704 | },
705 | "notification-url": "https://packagist.org/downloads/",
706 | "license": [
707 | "MIT"
708 | ],
709 | "authors": [
710 | {
711 | "name": "Ion Bazan",
712 | "email": "ion.bazan@gmail.com"
713 | },
714 | {
715 | "name": "Nicolas Grekas",
716 | "email": "p@tchwork.com"
717 | },
718 | {
719 | "name": "Symfony Community",
720 | "homepage": "https://symfony.com/contributors"
721 | }
722 | ],
723 | "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions",
724 | "homepage": "https://symfony.com",
725 | "keywords": [
726 | "compatibility",
727 | "polyfill",
728 | "portable",
729 | "shim"
730 | ],
731 | "support": {
732 | "source": "https://github.com/symfony/polyfill-php80/tree/v1.20.0"
733 | },
734 | "funding": [
735 | {
736 | "url": "https://symfony.com/sponsor",
737 | "type": "custom"
738 | },
739 | {
740 | "url": "https://github.com/fabpot",
741 | "type": "github"
742 | },
743 | {
744 | "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
745 | "type": "tidelift"
746 | }
747 | ],
748 | "time": "2020-10-23T14:02:19+00:00"
749 | }
750 | ],
751 | "packages-dev": [],
752 | "aliases": [],
753 | "minimum-stability": "stable",
754 | "stability-flags": [],
755 | "prefer-stable": false,
756 | "prefer-lowest": false,
757 | "platform": {
758 | "ext-json": "*"
759 | },
760 | "platform-dev": [],
761 | "plugin-api-version": "2.0.0"
762 | }
763 |
--------------------------------------------------------------------------------
/config/config.php:
--------------------------------------------------------------------------------
1 | request = Request::createFromGlobals();
26 | $this->telegram = new \Telegram($api);
27 | $this->result = $this->telegram->getData();
28 | $this->api = $api;
29 | $this->getChatId();
30 | $admins = explode(" ", $chatId);
31 | if (empty($this->chatId)) {
32 | $this->admId = $admins;
33 | $this->getPayload();
34 | foreach ($this->admId as $admin) {
35 | $this->sendMessage($admin);
36 | }
37 | } else {
38 | if (in_array($this->chatId, $admins)) {
39 | $this->sendTelegram($this->text);
40 | } else {
41 | $this->accessDenied();
42 | }
43 | }
44 | }
45 |
46 | public function getChatId()
47 | {
48 | $this->text = $this->result['message'] ['text'];
49 | $this->chatId = $this->result['message'] ['chat']['id'];
50 | $this->first = $this->telegram->FirstName();
51 | if (!is_null($this->telegram->Callback_ChatID())) {
52 | $this->callbackId = $this->telegram->Callback_ID();
53 | $callback = $this->telegram->Callback_Data();
54 | $this->sendCallbackResponse($callback);
55 | }
56 | }
57 |
58 | public function getPayload()
59 | {
60 | $this->payload = json_decode($this->request->request->get('payload'));
61 | if (is_null($this->request->server->get('HTTP_X_GITHUB_EVENT'))) {
62 | echo "invalid request";
63 | die;
64 | } else {
65 | $this->setMessage($this->request->server->get('HTTP_X_GITHUB_EVENT'));
66 | }
67 | }
68 |
69 | private function setMessage($typeEvent)
70 | {
71 | switch($typeEvent) {
72 | case 'push':
73 | $count = count($this->payload->commits);
74 | $noun = ($count > 1) ? "commits" : "commit";
75 | $this->message .= "⚙️ {$count} new {$noun} to {$this->payload->repository->name}:{$this->payload->repository->default_branch}\n\n";
76 | foreach ($this->payload->commits as $commit) {
77 | $commitId = substr($commit->id, -7);
78 | $this->message .= "url}\">{$commitId}: {$commit->message} by {$commit->author->name}\n";
79 | }
80 | $this->message .= "\nPushed by : {$this->payload->pusher->name}\n";
81 | break;
82 | case 'ping':
83 | $this->message .= "♻️ Connection Successful\n\n";
84 | break;
85 | case 'issues':
86 | if ($this->payload->action == "opened") {
87 | $this->message .= "⚠️ New Issue - payload->issue->html_url}\">{$this->payload->repository->full_name}#{$this->payload->issue->number}\n\n";
88 | $this->message .= "payload->issue->html_url}\">{$this->payload->issue->title} by payload->issue->user->html_url}\">@{$this->payload->issue->user->login}\n\n";
89 | $this->message .= " {$this->payload->issue->body}";
90 | } elseif ($this->payload->action == "closed") {
91 | $this->message .= "🚫 Issue Closed - payload->issue->html_url}\">{$this->payload->repository->full_name}#{$this->payload->issue->number}\n\n";
92 | $this->message .= "payload->issue->html_url}\">{$this->payload->issue->title} by payload->issue->user->html_url}\">@{$this->payload->issue->user->login}\n\n";
93 | $this->message .= " {$this->payload->issue->body}";
94 | }
95 | break;
96 | case 'pull_request':
97 | if ($this->payload->action == "opened") {
98 | $this->message .= "👷♂️🛠️ New Pull Request - payload->pull_request->html_url}\">{$this->payload->repository->full_name}#{$this->payload->pull_request->number}\n\n";
99 | $this->message .= "payload->pull_request->url}\">{$this->payload->pull_request->title} by payload->pull_request->user->html_url}\">@{$this->payload->pull_request->user->login}\n\n";
100 | $this->message .= " {$this->payload->pull_request->body}";
101 | } elseif ($this->payload->action == "closed") {
102 | $this->message .= "✅ Pull Request Merged - payload->pull_request->html_url}\">{$this->payload->repository->full_name}#{$this->payload->pull_request->number}\n\n";
103 | $this->message .= "payload->pull_request->html_url}\">{$this->payload->pull_request->title} by payload->pull_request->user->html_url}\">@{$this->payload->pull_request->user->login}\n\n";
104 | $this->message .= " {$this->payload->pull_request->body}";
105 | }
106 | break;
107 | case 'issue_comment':
108 | $this->message .= "📬 New comment on payload->comment->html_url}\">{$this->payload->repository->full_name}#{$this->payload->issue->number}\n\n";
109 | $this->message .= "payload->comment->html_url}\">comment by payload->comment->user->html_url}\">@{$this->payload->comment->user->login}\n\n";
110 | $this->message .= " {$this->payload->comment->body}";
111 | break;
112 | }
113 | }
114 |
115 | public function charReplace()
116 | {
117 | return str_replace(["\n"], ['%0A'], urlencode($this->message));
118 | }
119 |
120 | public function sendMessage($admin)
121 | {
122 | $text = $this->charReplace();
123 | $method_url = 'https://api.telegram.org/bot'.$this->api.'/sendMessage';
124 | $url = $method_url.'?chat_id='.$admin.'&disable_web_page_preview=1&parse_mode=html&text='.$text;
125 | $client = new Client();
126 | $response = $client->request('GET', $url);
127 | if ($response->getStatusCode() == 200) {
128 | return true;
129 | }
130 | return false;
131 | }
132 |
133 | public function sendTelegram($text)
134 | {
135 | switch($text) {
136 | case '/start':
137 | $img = curl_file_create('img/github.jpeg', 'image/png');
138 | $reply = "🙋🏻 Github Notify Bot 🤓\n\nHey {$this->first},\n\nI can send you notifications from your github Repository instantly to your Telegram. use /help for more information about me";
139 | $content = array('chat_id' => $this->chatId, 'photo' => $img, 'caption' => $reply, 'disable_web_page_preview' => true, 'parse_mode' => "HTML");
140 | $this->telegram->sendPhoto($content);
141 | break;
142 | case '/help':
143 | $option = [
144 | [$this->telegram->buildInlineKeyBoardButton($text = "📰 About", "", "about", ""), $this->telegram->buildInlineKeyBoardButton("📞 Contact", $url = "https://t.me/albinvar")],
145 | [$this->telegram->buildInlineKeyBoardButton("💠 Source Code", $url = "https://github.com/albinvar/Github-Telegram-Bot")]
146 | ];
147 | $keyb = $this->telegram->buildInlineKeyBoard($option);
148 | $reply = "Available Commands \n\n/id - To get chat id\n/host - To get Host Address\n/help - To show this Message\n/usage - How to use me\n\nSelect a command :";
149 | $content = array('chat_id' => $this->chatId, 'reply_markup' => $keyb, 'text' => $reply, 'disable_web_page_preview' => true, 'parse_mode' => "HTML");
150 | $this->telegram->sendMessage($content);
151 | break;
152 | case '/id':
153 | $reply = "Your id is {$this->chatId}
";
154 | $content = array('chat_id' => $this->chatId, 'text' => $reply, 'disable_web_page_preview' => true, 'parse_mode' => "HTML");
155 | $this->telegram->sendMessage($content);
156 | break;
157 | case '/host':
158 | $reply = "Server Address : {$_SERVER['REMOTE_ADDR']}";
159 | $content = array('chat_id' => $this->chatId, 'text' => $reply, 'disable_web_page_preview' => true, 'parse_mode' => "HTML");
160 | $this->telegram->sendMessage($content);
161 | break;
162 | case '/usage':
163 | $reply = "Adding webhook (Website Address) to your github repository\n\n 1) Redirect to Repository Settings->Set Webhook->Add Webhook \n 2) Set your payload url (heroku web address)\n 3) Set content type to \"application/x-www-form-urlencoded
\"\n\n Thats it. you will receive all notifications through me 🤗";
164 | $content = array('chat_id' => $this->chatId, 'text' => $reply, 'disable_web_page_preview' => true, 'parse_mode' => "HTML");
165 | $this->telegram->sendMessage($content);
166 | break;
167 | default:
168 | $reply = "🤨 Invalid Request";
169 | $content = array('chat_id' => $this->chatId, 'text' => $reply);
170 | $this->telegram->sendMessage($content);
171 |
172 | }
173 | }
174 |
175 | private function sendCallbackResponse($callback = null)
176 | {
177 | switch($callback) {
178 | case 'about':
179 | $reply = "Thanks for using our bot. \n\n The bot is designed to send notifications based on GitHub events from your github repo instantly to your Telegram account. \n\n Developed by @albinvar";
180 | $content = array('callback_query_id' => $this->callbackId, 'text' => $reply, 'show_alert' => true);
181 | $this->telegram->answerCallbackQuery($content);
182 | break;
183 |
184 | }
185 | }
186 |
187 | public function accessDenied()
188 | {
189 | $reply = "🔒 Access Denied to Bot 🚫\n\nPlease contact administrator for further information, Thank You..";
190 | $content = array('chat_id' => $this->chatId, 'text' => $reply, 'disable_web_page_preview' => true, 'parse_mode' => "HTML");
191 | $this->telegram->sendMessage($content);
192 | }
193 | }
194 |
--------------------------------------------------------------------------------