Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 405bece
Showing
23 changed files
with
2,365 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor/ | ||
.vscode/ | ||
Config.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace OxMohsen\TgBot; | ||
|
||
class Config | ||
{ | ||
/** | ||
* your bot token (get it from botfather). | ||
* | ||
* @var string | ||
*/ | ||
public const BOT_TOKEN = 'YOUR_BOT_TOKEN'; | ||
|
||
/** | ||
* your bot username `without @`. | ||
* | ||
* @var string | ||
*/ | ||
public const BOT_USERNAME = 'YOUR_BOT_USERNAME'; | ||
|
||
/** | ||
* Secret key required to access the webhook. | ||
* | ||
* @var string | ||
*/ | ||
public const SECRET = 'SUPPER_SECRET_TEXT'; | ||
|
||
/** | ||
* the url of webhook file. | ||
* | ||
* @var string | ||
*/ | ||
public const WEBHOOK_URL = 'https://your-domain/path/to/TgBot.php'; | ||
|
||
/** | ||
* the url of web app file. | ||
* | ||
* @var string | ||
*/ | ||
public const WEBAPP_URL = 'https://your-domain/path/to/web/index.html'; | ||
|
||
/** | ||
* all paths for your custom commands. | ||
* | ||
* @var array | ||
*/ | ||
public const COMMAND_PATH = [__DIR__ . '/MyCommands']; | ||
|
||
/** | ||
* all IDs of admin users. | ||
* | ||
* @var array | ||
*/ | ||
public const ADMINS = [123456789, 987654321]; | ||
|
||
|
||
/** | ||
* your MySQL database credentials. | ||
* | ||
* @var array | ||
*/ | ||
public const SQL_DB = [ | ||
'host' => '127.0.0.1', | ||
'user' => 'root', | ||
'password' => '', | ||
'database' => 'TgFontWebBot', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Mohsen Falakedin | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Longman\TelegramBot\Commands\SystemCommands; | ||
|
||
use Longman\TelegramBot\Commands\SystemCommand; | ||
use Longman\TelegramBot\Entities\ServerResponse; | ||
use Longman\TelegramBot\Exception\TelegramException; | ||
|
||
/** | ||
* Generic command. | ||
* | ||
* Gets executed for generic commands, when no other appropriate one is found. | ||
*/ | ||
class GenericCommand extends SystemCommand | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $name = 'generic'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $description = 'Handles generic commands or is executed by default when a command is not found'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $version = '1.0'; | ||
|
||
/** | ||
* Main command execution. | ||
* | ||
* @throws TelegramException | ||
* | ||
* @return ServerResponse | ||
*/ | ||
public function execute(): ServerResponse | ||
{ | ||
return $this->telegram->executeCommand('start'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Longman\TelegramBot\Commands\SystemCommands; | ||
|
||
use OxMohsen\TgBot\Messages; | ||
use Longman\TelegramBot\Commands\SystemCommand; | ||
use Longman\TelegramBot\Entities\ServerResponse; | ||
|
||
class GenericmessageCommand extends SystemCommand | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $name = 'genericmessage'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $description = 'Handle generic message'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $version = '1.0'; | ||
|
||
/** | ||
* Main command execution. | ||
* | ||
* @return ServerResponse | ||
*/ | ||
public function execute(): ServerResponse | ||
{ | ||
$web_app_data = $this->getMessage()->getWebAppData(); | ||
if ($web_app_data) { | ||
return $this->replyToChat( | ||
sprintf(Messages::WEBAPP_DATA_MESSAGE, $web_app_data->getData()), | ||
['parse_mode' => 'Markdown'] | ||
); | ||
} | ||
|
||
return $this->telegram->executeCommand('start'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Longman\TelegramBot\Commands\SystemCommands; | ||
|
||
use OxMohsen\TgBot\Config; | ||
use OxMohsen\TgBot\Messages; | ||
use Longman\TelegramBot\Entities\Keyboard; | ||
use Longman\TelegramBot\Entities\WebAppInfo; | ||
use Longman\TelegramBot\Commands\SystemCommand; | ||
use Longman\TelegramBot\Entities\KeyboardButton; | ||
use Longman\TelegramBot\Entities\ServerResponse; | ||
use Longman\TelegramBot\Exception\TelegramException; | ||
|
||
class StartCommand extends SystemCommand | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $name = 'start'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $description = 'start command'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $usage = '/start'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $version = '1.0'; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
protected $private_only = true; | ||
|
||
/** | ||
* Main command execution. | ||
* | ||
* @throws TelegramException | ||
* | ||
* @return ServerResponse | ||
*/ | ||
public function execute(): ServerResponse | ||
{ | ||
$keyboard = new Keyboard([ | ||
new KeyboardButton([ | ||
'text' => Messages::WEBAPP_KEYBOARD_TEXT, | ||
'web_app' => new WebAppInfo(['url' => Config::WEBAPP_URL]), | ||
]), | ||
]); | ||
$keyboard->setResizeKeyboard(true); | ||
|
||
return $this->replyToChat(Messages::START_MESSAGE, ['reply_markup' => $keyboard]); | ||
} | ||
} |
Oops, something went wrong.