Replies: 2 comments
-
|
I tested your bot logic and it works well. You need to provide more details. <?php
use WeStacks\TeleBot\Objects\Update;
use WeStacks\TeleBot\TeleBot;
require_once __DIR__ . '/vendor/autoload.php';
$bot = new TeleBot('<token>');
$bot->addHandler(function (TeleBot $bot, Update $update, callable $next) {
if ($update->message->text !== '/contact') {
return $next();
}
return $bot->sendMessage([
'chat_id' => $update->chat()->id,
'text' => 'Test contact',
'parse_mode' => 'MarkdownV2',
'reply_markup' => [
'keyboard' => [[[
'text' => 'Contact',
'request_contact' => true
]]],
'one_time_keyboard' => true,
'resize_keyboard' => true,
]
]);
});
$bot->addHandler(function (TeleBot $bot, Update $update, callable $next) {
if ($update->message->text !== '/start') {
return $next();
}
return $bot->sendMessage([
'chat_id' => $update->chat()->id,
'text' => 'Test start',
'parse_mode' => 'MarkdownV2',
'reply_markup' => [
'remove_keyboard' => true
]
]);
});
$last_offset = 0;
while (true) {
$updates = $bot->getUpdates([
'offset' => $last_offset + 1
]);
foreach ($updates as $update) {
$bot->handleUpdate($update);
$last_offset = $update->update_id;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
I use two handlers <?php
namespace App\Services\Telegram\Handler;
use WeStacks\TeleBot\Handlers\UpdateHandler;
use Illuminate\Support\Facades\Log;
class PhoneNumberHandler extends UpdateHandler
{
public function trigger()
{
if (empty($this->update->callback_query->data)) {
return false;
}
if($this->update->callback_query->data == 'activity') {
return true;
}
return false;
}
public function handle()
{
$this->sendChatAction([
'action' => 'typing'
]);
sleep(0.5);
return $this->sendMessage([
'text' => __("telebot.message.share"),
'parse_mode' => 'MarkdownV2',
'reply_markup' => [
'keyboard' => [
[
[
'text' => __('telebot.button.share'),
'request_contact' => true
]
],
],
'one_time_keyboard' => true,
'resize_keyboard' => true,
]
]);
}
}
}and I get contact in handler <?php
namespace App\Services\Telegram\Handler;
use WeStacks\TeleBot\Handlers\UpdateHandler;
use Illuminate\Support\Facades\Validator;
class CallHandler extends UpdateHandler
{
public function trigger()
{
if(isset($this->update->message->text) || isset($this->update->message->contact->phone_number)) {
return true;
}
return false;
}
public function handle()
{
$phone_number = isset($this->update->message->contact) ? $this->update->message->contact->phone_number : $this->update->message->text;
$validator = Validator::make(['phone_number' => $phone_number], [
'phone_number' => ['required', 'regex:/^([0-9\s\-\+\(\)]*)$/', 'min:10']
]);
if ($validator->fails()) {
return $this->sendMessage([
'text' => __("telebot.message.share"),
'parse_mode' => 'MarkdownV2',
'reply_markup' => [
'keyboard' => [
[
[
'text' => __('telebot.button.share'),
'request_contact' => true
]
],
],
'one_time_keyboard' => true,
'resize_keyboard' => true,
]
]);
} else {
$this->sendChatAction([
'action' => 'typing'
]);
sleep(0.5);
return $this->sendMessage([
'text' => __("telebot.message.join"),
'parse_mode' => 'MarkdownV2',
'reply_markup' => [
'remove_keyboard' => true,
'inline_keyboard' => [
[
[
'text' => __('telebot.button.join'),
'url' => "https://domain.com/join?phone_number=$phone_number",
],
]
],
]
]);
}
}
}but, after sending the contact I see the share contact button |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, friend!
I want to remove the button (ReplyKeyboardMarkup).
I send a button with a message:
I want to remove this button by running the command
/start. But it doesn't workСan you send an example for me? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions