Skip to content

Commit

Permalink
fix: update phpdoc interfaces and change the request type for send no…
Browse files Browse the repository at this point in the history
…tification method
  • Loading branch information
tanhongit committed Oct 17, 2023
1 parent 2c10816 commit 970fd0e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/Interfaces/EventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LbilTech\TelegramGitNotifier\Interfaces;

use LbilTech\TelegramGitNotifier\Trait\ActionEventTrait;
use Symfony\Component\HttpFoundation\Request;

interface EventInterface
Expand All @@ -12,7 +13,7 @@ interface EventInterface
* @param $payload
*
* @return string
* @see EventTrait::getActionOfEvent()
* @see ActionEventTrait::getActionOfEvent()
*/
public function getActionOfEvent($payload): string;

Expand Down
10 changes: 10 additions & 0 deletions src/Interfaces/Structures/AppInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface AppInterface
*
* @return void
* @throws MessageIsEmptyException
* @see App::sendMessage()
*/
public function sendMessage(
string $message = '',
Expand All @@ -29,6 +30,7 @@ public function sendMessage(
*
* @return void
* @throws EntryNotFoundException
* @see App::sendPhoto()
*/
public function sendPhoto(string $photo = '', string $caption = ''): void;

Expand All @@ -39,6 +41,7 @@ public function sendPhoto(string $photo = '', string $caption = ''): void;
*
* @return void
* @throws MessageIsEmptyException
* @see App::answerCallbackQuery()
*/
public function answerCallbackQuery(string $text = null): void;

Expand All @@ -49,6 +52,7 @@ public function answerCallbackQuery(string $text = null): void;
* @param array $options
*
* @return void
* @see App::editMessageText()
*/
public function editMessageText(
?string $text = null,
Expand All @@ -61,13 +65,15 @@ public function editMessageText(
* @param array $options
*
* @return void
* @see App::editMessageReplyMarkup()
*/
public function editMessageReplyMarkup(array $options = []): void;

/**
* Get the text from callback message
*
* @return string
* @see App::getCallbackTextMessage()
*/
public function getCallbackTextMessage(): string;

Expand All @@ -77,27 +83,31 @@ public function getCallbackTextMessage(): string;
* @param array $options
*
* @return array
* @see App::setCallbackContentMessage()
*/
public function setCallbackContentMessage(array $options = []): array;

/**
* @param string $chatId
*
* @return void
* @see App::setCurrentChatBotId()
*/
public function setCurrentChatBotId(string $chatId): void;

/**
* Get the username of the bot
*
* @return string|null
* @see App::getBotName()
*/
public function getBotName(): ?string;

/**
* Get the command message from a telegram
*
* @return string
* @see App::getCommandMessage()
*/
public function getCommandMessage(): string;
}
7 changes: 5 additions & 2 deletions src/Interfaces/Structures/NotificationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface NotificationInterface
*
* @return void
* @throws InvalidViewTemplateException
* @see Notification::accessDenied()
*/
public function accessDenied(
string $chatId = null,
Expand All @@ -30,19 +31,21 @@ public function accessDenied(
*
* @return mixed|void
* @throws InvalidViewTemplateException
* @see Notification::setPayload()
*/
public function setPayload(Request $request, string $event);

/**
* Send notification to telegram
*
* @param string $chatId
* @param string|null $message
* @param array $options
*
* @return bool
* @throws SendNotificationException
* @see Notification::sendNotify()
*/
public function sendNotify(string $chatId, string $message = null): bool;
public function sendNotify(string $message = null, array $options = []): bool;

/**
* Get action name of event from payload data
Expand Down
21 changes: 7 additions & 14 deletions src/Structures/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,18 @@ private function setMessage(string $typeEvent): void
]);
}

public function sendNotify(string $chatId, string $message = null): bool
public function sendNotify(string $message = null, array $options = []): bool
{
if (!is_null($message)) {
$this->message = $message;
}
$this->message = $message ?? $this->message;

$queryParams = [
'chat_id' => $chatId,
'disable_web_page_preview' => 1,
'parse_mode' => 'html',
'text' => $this->message
];
$queryParams = array_merge($this->createTelegramBaseContent(), ['text' => $this->message], $options);

$url = 'https://api.telegram.org/bot'
. config('telegram-git-notifier.bot.token') . '/sendMessage'
. '?' . http_build_query($queryParams);
$url = 'https://api.telegram.org/bot' . config('telegram-git-notifier.bot.token') . '/sendMessage';

try {
$response = $this->client->request('GET', $url);
$response = $this->client->request('POST', $url, [
'form_params' => $queryParams
]);

if ($response->getStatusCode() === 200) {
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/Trait/EventSettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public function eventMarkup(
$replyMarkup = $replyMarkupItem = [];

$this->event->setEventConfig($platform);
$events = $parentEvent === null ? $this->event->eventConfig
: $this->event->eventConfig[$parentEvent];
$events = $parentEvent === null ? $this->event->getEventConfig()
: $this->event->getEventConfig()[$parentEvent];

foreach ($events as $key => $value) {
if (count($replyMarkupItem) === SettingConstant::BTN_LINE_ITEM_COUNT) {
Expand Down

0 comments on commit 970fd0e

Please sign in to comment.