Core: user send text line "hello" bot answer it "hi" how can it do it

Created on 9 Oct 2016  路  5Comments  路  Source: php-telegram-bot/core

Required Information

  • PHP version:
  • PHP Telegram Bot version:
  • Using MySQL database: yes / no
  • Update Method: Webhook / getUpdates
  • Self-signed certificate: yes / no
  • RAW update (if available):

    Expected behaviour

What SHOULD be happening?

Actual behaviour

What IS happening?

Steps to reproduce

Explain how to reproduce the issue

Extra details

Please post any extra details that might help solve the issue (e.g. logs)

All 5 comments

    public function execute() {
        $message = $this->getMessage();
        $text = $message->getText();
        $chat_id = $message->getChat()->getId();

        $data = [];
        $data['chat_id'] = $chat_id;

        if (str_replace('/hello ', '', $text) == 'Hello') {
            $message = 'Hi!';
        } else {
            $message = 'What you say ?';
        }

        $data['text'] = $message;
        return Request::sendMessage($data);
    }

Solved? con we close?

thank you for your answer. but i do not realize .
my user send '爻賱丕賲' in bot how can i get this massage and answer it '丿乇賵丿'
thank for your replay :) 馃憤

Is this what you want?

class GenericmessageCommand extends SystemCommand
{
    public function execute()
    {
        $message = $this->getMessage();

        if ($message && strpos($message->getText(true), '爻賱丕賲')) {
            return Request::sendMessage(
                [
                    'chat_id' => $message->getChat()->getId(),
                    'text' => '丿乇賵丿'
                ]
            );
        }

        return Request::emptyResponse();
    }
}

thank an Ocean 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dorcu picture dorcu  路  3Comments

esomkin picture esomkin  路  3Comments

sineverba picture sineverba  路  3Comments

nesttle picture nesttle  路  4Comments

NabiKAZ picture NabiKAZ  路  4Comments