telegram-bot-sdk icon indicating copy to clipboard operation
telegram-bot-sdk copied to clipboard

Referral link /start and passing param

Open erfanhemmati opened this issue 4 years ago • 2 comments

@irazasyed How can i create a Telegram Referral Link like t.me/abcdbot?start=123 and getting 123 value in the bot?! can we use Telegram deep links?

erfanhemmati avatar Dec 07 '20 14:12 erfanhemmati

I think u cant, becouse the comand /start type only from app.

xdendev avatar Mar 02 '21 08:03 xdendev

@irazasyed How can i create a Telegram Referral Link like t.me/abcdbot?start=123 and getting 123 value in the bot?! can we use Telegram deep links?

here is my working Laravel code example if anyone needs this: `<?php

namespace App\TelegramCommands;

use Telegram\Bot\Actions; use Telegram\Bot\Commands\Command;

class StartCommand extends Command {

/**
 * Command name
 *
 * @var string
 */
protected $name = 'start';

/**
 * Command description
 *
 * @var string
 */
protected $description = 'Your description';

/**
 * Command arguments object decoding pattern (/start {variable}) that can be later accessed and processed
 * This will work both with /start variable and https://t.me/your_bot?start=variable
 *
 * @var string
 */
protected $pattern = '{variable}';

/**
 * Process command
 *
 * @return void
 */
public function handle()
{
    //get arguments sent with command
    $arguments = (object) $this->getArguments();

    //check for arguments defined in $pattern
    if (isset($arguments->variable)) {
        Log::debug($arguments->variable)
    } else {
        Log::debug('no variable was passed')
    }
}

}`

theveloperspl avatar Nov 06 '21 20:11 theveloperspl