defstudio / telegraph

Telegraph is a Laravel package for fluently interacting with Telegram Bots
MIT License
675 stars 116 forks source link

How to make button which suggests user to share his phone number? #480

Closed musobekmadrimov closed 8 months ago

musobekmadrimov commented 8 months ago

Hello, everyone! I am new in this pacakge! How to make button which suggests user to share his phone number? I tried $phone_number = $this->message->contact()->phoneNumber() but getting this error: Call to a member function phoneNumber().

Also I need the correct version of recieving users phone number to save it to DB.

Please, help!

musobekmadrimov commented 8 months ago

Sorry, I found it. But now faced another problem.

    public function start(): void
    {
        $name = $this->message->from()->firstName() . " " . $this->message->from()->lastName();
        $this->reply("");
        Telegraph::chat($this->chat)->message("Assalamu alaykum {$name} 👋🏻, sizni ko'rib turganimizdan xursandmiz, iltimos, telefon raqamingizni tasdiqlash maqsadida quyidagi tugmachani bossangiz:")
            ->keyboard(Keyboard::make()->buttons([
                Button::make('✅ Boshlash')->action('getPhoneNumber'),
            ]))->send();
    }

    public function getPhoneNumber(): void
    {
        Telegraph::chat($this->chat)->message("Telefon raqamni ulashish")
            ->replyKeyboard(
                ReplyKeyboard::make()->buttons([
                    ReplyButton::make("🌐 Telefon raqamni ulashish")->requestContact(),
                ])->oneTime(true)->resize()
            )->send();
    }

From getPhoneNumber method how to assign client phone number? I need do some logic and save it to database! Please, help with this!