Skip to content

Commit

Permalink
Use camelCase and fix small issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Julielesss committed Nov 21, 2019
1 parent fa5dbe4 commit 3bc1bf2
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/channels/TelegramChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@

class TelegramChannel extends Component implements ChannelInterface
{
/**
* @var BaseActiveRecord|string
*/
public $model = 'app\additional\notification\Notification';

/**
* @var Client|array|string
*/
Expand All @@ -25,7 +20,7 @@ class TelegramChannel extends Component implements ChannelInterface
/**
* @var string
*/
public $api_url = "https://api.telegram.org/bot";
public $apiUrl = "https://api.telegram.org/";

/**
* @var string
Expand All @@ -35,26 +30,26 @@ class TelegramChannel extends Component implements ChannelInterface
/**
* @var string
*/
public $bot_token;
public $botToken;

/**
* @var string
*/
public $parse_mode = null;
public $parseMode = null;

const PARSE_MODE_HTML = "HTML";

const PARSE_MODE_MARKDOWN = "Markdown";

/**
* @var bool
* If you need to change silent_mode, you can use this code before calling telegram channel
* If you need to change silentMode, you can use this code before calling telegram channel
*
* \Yii::$container->set('\app\additional\notification\TelegramChannel', [
* 'silent_mode' => true,
* 'silentMode' => true,
* ]);
*/
public $silent_mode = false;
public $silentMode = false;

/**
* @throws \yii\base\InvalidConfigException
Expand All @@ -63,13 +58,14 @@ public function init()
{
parent::init();

if(!isset($this->bot_id) || !isset($this->bot_token)){
if(!isset($this->bot_id) || !isset($this->botToken)){
throw new InvalidConfigException("Bot id or bot token is undefined");
}

if (!isset($this->httpClient)) {
$this->httpClient = [
'class' => Client::className(),
'baseUrl' => $this->apiUrl
];
}
$this->httpClient = Instance::ensure($this->httpClient, Client::className());
Expand All @@ -95,22 +91,21 @@ public function send(NotifiableInterface $recipient, NotificationInterface $noti
$data = [
"chat_id" => $chat_id,
"text" => $text,
'disable_notification' => $this->silent_mode
'disable_notification' => $this->silentMode
];
if($this->parse_mode != null){
$data["parse_mode"] = $this->parse_mode;
if($this->parseMode != null){
$data["parse_mode"] = $this->parseMode;
}

$resultUrl = $this->createUrl();
return $this->httpClient->createRequest()
->setMethod('post')
->setUrl($resultUrl)
->setUrl($this->createUrl())
->setData($data)
->send();
}

private function createUrl()
{
return $this->api_url . $this->bot_id . ":" . $this->bot_token . "/sendmessage";
return "bot" . $this->bot_id . ":" . $this->botToken . "/sendmessage";
}
}

0 comments on commit 3bc1bf2

Please sign in to comment.