Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 69 additions & 2 deletions routes/telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use SergiX44\Nutgram\Nutgram;
use App\Telegram\Middleware\CheckUserRegister;
use SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardMarkup;
use SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardButton;

/*
|--------------------------------------------------------------------------
Expand All @@ -19,13 +21,19 @@
$bot->onCommand('start', function (Nutgram $bot) {
$user = $bot->getGlobalData('user');

$mainMenuKeyboard = InlineKeyboardMarkup::make()
->addRow(
InlineKeyboardButton::make('👤 پروفایل')->callbackData('profile'),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the text is repeated more, move it to the lang files.

InlineKeyboardButton::make('ℹ️ راهنما')->callbackData('help'),
);

if ($user) {
$message = "سلام {$user->full_name}! 👋\n";
$message .= "به ربات خوش آمدید!";

$bot->sendMessage($message);
$bot->sendMessage($message, reply_markup: $mainMenuKeyboard);
} else {
$bot->sendMessage('خطا در ثبت‌نام کاربر!');
$bot->sendMessage('خطا در ثبت‌نام کاربر!', reply_markup: $mainMenuKeyboard);
}
})->description('The start command!');

Expand All @@ -49,6 +57,65 @@
}
});

// Inline keyboard callbacks
$bot->onCallbackQueryData('profile', function (Nutgram $bot) {
$bot->answerCallbackQuery();

$user = $bot->getGlobalData('user');
if ($user) {
$message = "👤 اطلاعات پروفایل:\n\n";
$message .= "نام: {$user->first_name}\n";
$message .= "نام خانوادگی: {$user->last_name}\n";
$message .= "نام کامل: {$user->full_name}\n";
$message .= "آیدی تلگرام: {$user->telegram_id}\n";

if ($user->data && isset($user->data['username'])) {
$message .= "نام کاربری: @{$user->data['username']}\n";
}

$backKeyboard = InlineKeyboardMarkup::make()
->addRow(
InlineKeyboardButton::make('⬅️ بازگشت')->callbackData('back_main')
);

$bot->editMessageText($message, reply_markup: $backKeyboard);
} else {
$bot->answerCallbackQuery(text: 'خطا در دریافت اطلاعات کاربر!', show_alert: true);
}
});

$bot->onCallbackQueryData('help', function (Nutgram $bot) {
$bot->answerCallbackQuery();

$message = "ℹ️ راهنما:\n\n";
$message .= "از دکمه‌های زیر برای ناوبری استفاده کنید.\n";
$message .= "برای شروع دوباره، از دکمه بازگشت استفاده کنید.";

$backKeyboard = InlineKeyboardMarkup::make()
->addRow(
InlineKeyboardButton::make('⬅️ بازگشت')->callbackData('back_main')
);

$bot->editMessageText($message, reply_markup: $backKeyboard);
});

$bot->onCallbackQueryData('back_main', function (Nutgram $bot) {
$bot->answerCallbackQuery();

$user = $bot->getGlobalData('user');
$message = $user
? "سلام {$user->full_name}! 👋\nبه ربات خوش آمدید!"
: 'به ربات خوش آمدید!';

$mainMenuKeyboard = InlineKeyboardMarkup::make()
->addRow(
InlineKeyboardButton::make('👤 پروفایل')->callbackData('profile'),
InlineKeyboardButton::make('ℹ️ راهنما')->callbackData('help'),
);

$bot->editMessageText($message, reply_markup: $mainMenuKeyboard);
});


$bot->onGroupChatCreated(function (Nutgram $bot) {
$bot->sendMessage('test');
Expand Down