Skip to content

Commit

Permalink
pass generator web bot
Browse files Browse the repository at this point in the history
  • Loading branch information
OxMohsen committed Apr 27, 2022
0 parents commit 405bece
Show file tree
Hide file tree
Showing 23 changed files with 2,365 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
@@ -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
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
vendor/
.vscode/
Config.php
68 changes: 68 additions & 0 deletions Config-example.php
@@ -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',
];
}
21 changes: 21 additions & 0 deletions LICENSE
@@ -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.
42 changes: 42 additions & 0 deletions MyCommands/GenericCommand.php
@@ -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');
}
}
43 changes: 43 additions & 0 deletions MyCommands/GenericmessageCommand.php
@@ -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');
}
}
60 changes: 60 additions & 0 deletions MyCommands/StartCommand.php
@@ -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]);
}
}

0 comments on commit 405bece

Please sign in to comment.