php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.87k stars 951 forks source link

Create custom command and keyboard #58

Closed sanjarani closed 8 years ago

sanjarani commented 8 years ago

Hi; Thanks for this cool script. :+1:

I wish that I could find more detailed documentation for your script.

I started to use your script recently and everything seems nice BUT need to know : How can I write my own commands? I did create a class named testCommand in commands folder but this way didn't work.

Would you please help me to create my own command and custom keyboard?

_Thanks in Advance_

sanjarani commented 8 years ago

First problem solved.

I did made my command filename in lower case :

Wrong way
**t**estCommand.php
Right way
**T**estCommand.php Well, now I need to learn how can I create my own custom keyboard? Would you please help me?
sanjarani commented 8 years ago

OK, Second problem Solved.

KeyboardCommand.php in examples/Commands/ was Checked and this is the solution :

first of all, use dependencies for reply_markup:

use Longman\TelegramBot\Entities\ReplyKeyboardMarkup;
use Longman\TelegramBot\Entities\ReplyKeyboardHide;
use Longman\TelegramBot\Entities\ForceReply;

and then, prepare a variable named $keyboards :

        $keyboards = array();

And next step is styling custom keyboard using an array named $keyboard:

        $keyboard[] = ['7','8','9'];
        $keyboard[] = ['4','5','6'];
        $keyboard[] = ['1','2','3'];
        $keyboard[] = [' ','0',' '];

In next step, you have to pass $keyboard array to $keyboard_s_ and unset $keyboard :

        $keyboards[] = $keyboard;
        unset($keyboard);

Now initiate ReplyKeyboardMarkup :

        $reply_keyboard_markup = new ReplyKeyboardMarkup(
            [
                'keyboard' => $keyboards[0] ,
                'resize_keyboard' => true,
                'one_time_keyboard' => false,
                'selective' => false
            ]
        );

And at last simply add this to send parameters using :

        $data['reply_markup'] = $reply_keyboard_markup;

This is very cool script and just need more documentations.

Well Done...

MBoretto commented 8 years ago

Thanks, for trying it! It would be great if you could start write a wiki page with this recipe to build custom commands!

sanjarani commented 8 years ago

Your welcome... I'll do it... Please correct me if I did understand something wrong.

MBoretto commented 8 years ago

I've seen the page good job! Thanks again! On 2 Dec 2015 18:12, "Kiyarash Sanjarani Vahed" notifications@github.com wrote:

Your welcome... I'll do it... Please correct me if I did understand something wrong.

— Reply to this email directly or view it on GitHub https://github.com/akalongman/php-telegram-bot/issues/58#issuecomment-161367984 .