Longman\TelegramBot\Commands\UserCommands\WeatherCommand::execute PHP Method

execute() public method

Command execute method
public execute ( ) : mixed
return mixed
    public function execute()
    {
        $message = $this->getMessage();
        $chat_id = $message->getChat()->getId();
        $text = '';
        if (trim($this->getConfig('owm_api_key'))) {
            $location = trim($message->getText(true));
            if ($location !== '') {
                if ($weather_data = json_decode($this->getWeatherData($location), true)) {
                    $text = $this->getWeatherString($weather_data);
                }
                if ($text === '') {
                    $text = 'Cannot find weather for location: ' . $location;
                }
            } else {
                $text = 'You must specify location in format: /weather <city>';
            }
        } else {
            $text = 'OpenWeatherMap API key not defined.';
        }
        $data = ['chat_id' => $chat_id, 'text' => $text];
        return Request::sendMessage($data);
    }