Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit e9692ab

Browse files
committed
Publish
0 parents  commit e9692ab

36 files changed

+2735
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
/data/*

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM kimbtechnologies/php_nginx:latest
2+
3+
# copy into webroot
4+
COPY ./other/hook.php /php-code/hook.php
5+
COPY ./other/index.php /php-code/index.php
6+
7+
# startup file
8+
COPY ./other/*.sh /
9+
10+
# copy bot
11+
COPY ./bot/ /code/bot/
12+
13+
# prepare container, download ttt, install composer
14+
RUN mkdir /code/ttt/ && mkdir /code/data/ \
15+
&& apk add --update --no-cache git su-exec \
16+
&& sh /install-ttt.sh && rm /install-ttt.sh \
17+
&& sh /install-bot.sh && rm /install-bot.sh

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# TaskTimeTerminate Telegram Bot
2+
3+
> A Telegram Bot providing a TaskTimeTerminate-Client.
4+
> See https://github.com/KIMB-technologies/TaskTimeTerminate for information about TTT
5+
6+
## Installation
7+
1. Copy the [docker-compose.yml](https://github.com/KIMB-technologies/TaskTimeTerminateBot/blob/master/docker-compose.yml)
8+
2. Make sure to bind to a free port
9+
3. Change the volume to a location wich is regularly made a backup from. (Inside the container all data is stored in `/code/data`)
10+
4. Edit environment variables
11+
- `DEVMODE` Should always be `false` (enables error messages)
12+
- `WEBHOOK_URL` The URL where Telegram sends Webhook requests (needs https); URL to the webroot of this container
13+
- `WEBHOOK_UNREGISTER` Bot will register webhook if `false` and unregister if `true` (check always done on container startup)
14+
- `REGISTER_TOKEN` To use the bot a user will need a token and run `/start <token>`; specify the token here
15+
- `TELEGRAM_API_KEY` The Telegram API Key
16+
- `TELEGRAM_BOT_NAME` The Username of the Telegram Bot (without `@`)
17+
3. NGINX Reverse Proxy for Hook
18+
- Example for Nginx reverse proxy
19+
```nginx
20+
location /telegrambot/ITYFNobd7CfNRd8ojFzhrNhFJ2dSEfai41mwc3KqzXlOTgia6M/ {
21+
proxy_pass http://127.0.0.1:8080/;
22+
proxy_http_version 1.1;
23+
proxy_read_timeout 3m;
24+
proxy_send_timeout 3m;
25+
}
26+
```
27+
5. Start the bot in Telegram and use like local TTT-Client.

VERSION

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
latest
2+
0.1.0
3+
0.1
4+
0

bot/Commands/GenericCommand.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* TaskTimeTerminate Telegram Bot
5+
* https://github.com/KIMB-technologies/TaskTimeTerminate-Bot
6+
*
7+
* (c) 2020 KIMB-technologies
8+
* https://github.com/KIMB-technologies/
9+
*
10+
* released under the terms of GNU Public License Version 3
11+
* https://www.gnu.org/licenses/gpl-3.0.txt
12+
*
13+
* The project is based on
14+
* https://github.com/php-telegram-bot/example-bot/
15+
* (c) PHP Telegram Bot Team
16+
* released under the terms of MIT License
17+
* https://github.com/php-telegram-bot/example-bot/blob/master/LICENSE
18+
*/
19+
20+
namespace Longman\TelegramBot\Commands\SystemCommands;
21+
22+
use Longman\TelegramBot\Commands\SystemCommand;
23+
use Longman\TelegramBot\Entities\ServerResponse;
24+
use Longman\TelegramBot\Exception\TelegramException;
25+
26+
class GenericCommand extends SystemCommand
27+
{
28+
29+
protected $name = 'generic';
30+
protected $description = 'Generic fallback command';
31+
protected $version = '1.0.0';
32+
protected $private_only = false;
33+
34+
public function execute(): ServerResponse
35+
{
36+
return $this->replyToChat(
37+
'This is not a command for this bot.' . PHP_EOL .
38+
'Use one of /start, /ttt or /task!'
39+
);
40+
}
41+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
/**
4+
* TaskTimeTerminate Telegram Bot
5+
* https://github.com/KIMB-technologies/TaskTimeTerminate-Bot
6+
*
7+
* (c) 2020 KIMB-technologies
8+
* https://github.com/KIMB-technologies/
9+
*
10+
* released under the terms of GNU Public License Version 3
11+
* https://www.gnu.org/licenses/gpl-3.0.txt
12+
*
13+
* The project is based on
14+
* https://github.com/php-telegram-bot/example-bot/
15+
* (c) PHP Telegram Bot Team
16+
* released under the terms of MIT License
17+
* https://github.com/php-telegram-bot/example-bot/blob/master/LICENSE
18+
*/
19+
20+
namespace Longman\TelegramBot\Commands\SystemCommands;
21+
22+
use Longman\TelegramBot\Commands\SystemCommand;
23+
use Longman\TelegramBot\Entities\ServerResponse;
24+
use Longman\TelegramBot\Request;
25+
26+
class GenericmessageCommand extends SystemCommand
27+
{
28+
29+
protected $name = 'genericmessage';
30+
protected $description = 'Generic fallback message';
31+
protected $version = '1.0.0';
32+
33+
public function execute(): ServerResponse
34+
{
35+
/**
36+
* Authenticate
37+
*/
38+
$chat = $this->getMessage()->getChat();
39+
if(!$chat->isPrivateChat()){
40+
return $this->replyToUser('This bot is for usage in private Chats only!');
41+
}
42+
$session = new \TTTBot\Session($chat->getId());
43+
if(!$session->getData('registered')){
44+
return $this->replyToUser('Please start the bot via /start!');
45+
}
46+
47+
/**
48+
* Handle message
49+
*/
50+
$handler = $session->getTemp('messageHandler');
51+
if($handler === false){
52+
return $this->replyToUser('Please use the commands /ttt and /task!');
53+
}
54+
else{
55+
$text = $this->getMessage()->getText(true);
56+
57+
switch($handler) {
58+
case "categoryAdd":
59+
if(\TTTBot\InputParser::checkCategoryInput($text)){
60+
\TTTBot\TTTLoader::addReadlineValue($session->getTemp('readlineName'), $text);
61+
$command = array('c','cats','add');
62+
}
63+
else{
64+
return $this->replyToChat('Invalid category name!');
65+
}
66+
break;
67+
case "categoryDel":
68+
if(is_numeric($text)){
69+
\TTTBot\TTTLoader::addReadlineValue($session->getTemp('readlineName'), $text);
70+
$command = array('c','cats','del');
71+
}
72+
else{
73+
return $this->replyToChat('Invalid category ID!');
74+
}
75+
break;
76+
case "editSync":
77+
$r = \TTTBot\SettingsHelper::syncStep($session, $text);
78+
if($r === true){
79+
$command = array('c','sync','server');
80+
}
81+
else{
82+
return $this->replyToChat($r);
83+
}
84+
break;
85+
case "editData":
86+
$r = \TTTBot\SettingsHelper::editStep($session, $text);
87+
if($r === true){
88+
$command = array('c','e', $session->getTemp('editDay'));
89+
}
90+
else{
91+
return $this->replyToChat($r);
92+
}
93+
break;
94+
case "newTask":
95+
$th = new \TTTBot\AddTaskHelper($session);
96+
$th->messageCommand($text);
97+
$opts = array('parse_mode' => 'Markdown');
98+
if(!is_null($th->getReplyKeyboard())){
99+
$opts['reply_markup'] = $th->getReplyKeyboard();
100+
}
101+
return $this->replyToChat($th->getReplyText(), $opts);
102+
default:
103+
return $this->replyToChat('Unknown message handler – this should not have happened!');
104+
break;
105+
}
106+
107+
$session->setTemp('messageHandler', false);
108+
\TTTBot\TTTLoader::loadTTT('/code/data/' . $session->getKey());
109+
$output = \TTTBot\TTTLoader::runTTTCommand($command);
110+
return $this->replyToUser(
111+
$output,
112+
array('parse_mode' => 'Markdown')
113+
);
114+
}
115+
}
116+
}

bot/Commands/StartCommand.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/**
4+
* TaskTimeTerminate Telegram Bot
5+
* https://github.com/KIMB-technologies/TaskTimeTerminate-Bot
6+
*
7+
* (c) 2020 KIMB-technologies
8+
* https://github.com/KIMB-technologies/
9+
*
10+
* released under the terms of GNU Public License Version 3
11+
* https://www.gnu.org/licenses/gpl-3.0.txt
12+
*
13+
* The project is based on
14+
* https://github.com/php-telegram-bot/example-bot/
15+
* (c) PHP Telegram Bot Team
16+
* released under the terms of MIT License
17+
* https://github.com/php-telegram-bot/example-bot/blob/master/LICENSE
18+
*/
19+
20+
namespace Longman\TelegramBot\Commands\SystemCommands;
21+
22+
use Longman\TelegramBot\Commands\SystemCommand;
23+
use Longman\TelegramBot\Entities\ServerResponse;
24+
use Longman\TelegramBot\Exception\TelegramException;
25+
26+
class StartCommand extends SystemCommand
27+
{
28+
29+
protected $name = 'start';
30+
protected $description = 'Start the bot';
31+
protected $usage = '/start';
32+
protected $version = '1.0.0';
33+
protected $private_only = false;
34+
35+
public function execute(): ServerResponse
36+
{
37+
$chat = $this->getMessage()->getChat();
38+
if(!$chat->isPrivateChat()){
39+
return $this->replyToUser('This bot is for usage in private Chats only!');
40+
}
41+
42+
$session = new \TTTBot\Session($chat->getId());
43+
if($session->getData('registered')){
44+
return $this->replyToUser('You have started the bot already. Use /ttt or /task!');
45+
}
46+
else {
47+
$token = $this->getMessage()->getText(true);
48+
if( empty($token) ){
49+
return $this->replyToUser(
50+
'This bot requires you to register for the usage. Please get a token from your admin or host your own version!' . PHP_EOL .
51+
'https://github.com/KIMB-technologies/TaskTimeTerminate-Bot' . PHP_EOL . PHP_EOL .
52+
'If you have a token please run: ' . PHP_EOL .
53+
"\t/start token"
54+
);
55+
}
56+
else if( $token !== \TTTBot\Config::getUserRegisterToken() ) {
57+
return $this->replyToUser('You entered an incorrect token for registration!');
58+
}
59+
else{
60+
$session->setData('registered', true);
61+
return $this->replyToUser('Registration successful! Use /ttt or /task! now');
62+
}
63+
}
64+
}
65+
}

bot/Commands/TaskCommand.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/**
4+
* TaskTimeTerminate Telegram Bot
5+
* https://github.com/KIMB-technologies/TaskTimeTerminate-Bot
6+
*
7+
* (c) 2020 KIMB-technologies
8+
* https://github.com/KIMB-technologies/
9+
*
10+
* released under the terms of GNU Public License Version 3
11+
* https://www.gnu.org/licenses/gpl-3.0.txt
12+
*
13+
* The project is based on
14+
* https://github.com/php-telegram-bot/example-bot/
15+
* (c) PHP Telegram Bot Team
16+
* released under the terms of MIT License
17+
* https://github.com/php-telegram-bot/example-bot/blob/master/LICENSE
18+
*/
19+
20+
namespace Longman\TelegramBot\Commands\SystemCommands;
21+
22+
use Longman\TelegramBot\Commands\SystemCommand;
23+
use Longman\TelegramBot\Entities\ServerResponse;
24+
use Longman\TelegramBot\Exception\TelegramException;
25+
26+
27+
class TaskCommand extends SystemCommand
28+
{
29+
30+
protected $name = 'task';
31+
protected $description = 'Main Task Command';
32+
protected $usage = '/task';
33+
protected $version = '1.0.0';
34+
protected $private_only = false;
35+
36+
public function execute(): ServerResponse
37+
{
38+
/**
39+
* Authenticate
40+
*/
41+
$chat = $this->getMessage()->getChat();
42+
if(!$chat->isPrivateChat()){
43+
return $this->replyToUser('This bot is for usage in private Chats only!');
44+
}
45+
$session = new \TTTBot\Session($chat->getId());
46+
if(!$session->getData('registered')){
47+
return $this->replyToUser('Please start the bot via /start!');
48+
}
49+
50+
/**
51+
* Handle new Tasks
52+
*/
53+
54+
$text = $this->getMessage()->getText(true);
55+
56+
$th = new \TTTBot\AddTaskHelper($session);
57+
$th->taskCommand($text);
58+
59+
$opts = array('parse_mode' => 'Markdown');
60+
if(!is_null($th->getReplyKeyboard())){
61+
$opts['reply_markup'] = $th->getReplyKeyboard();
62+
}
63+
return $this->replyToChat($th->getReplyText(), $opts);
64+
65+
}
66+
}

0 commit comments

Comments
 (0)