Skip to content

Commit

Permalink
Merge pull request #44 from tanhongit/refactor-events
Browse files Browse the repository at this point in the history
(#33) update template message for some events v6
  • Loading branch information
tanhongit authored Jun 28, 2023
2 parents c0fa87b + a4cc523 commit 5d7b49e
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 11 deletions.
23 changes: 23 additions & 0 deletions resources/events/pull_request/closed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* @var $payload mixed
*/

$message = '✅ <b>Pull Request Merged';
if (!isset($payload->pull_request->merged) || $payload->pull_request->merged !== true) {
$message = '❌ <b>Pull Request Closed';
}

$message = $message . "</b> - <a href=\"{$payload->pull_request->html_url}\">{$payload->repository->full_name}#{$payload->pull_request->number}</a> by <a href=\"{$payload->pull_request->user->html_url}\">@{$payload->pull_request->user->login}</a>\n\n";

$message .= "🛠 <b>{$payload->pull_request->title}</b> \n\n";

if (isset($payload->pull_request->assignee)) {
$message .= "🙋 Assignee: <a href=\"{$payload->pull_request->assignee->html_url}\">@{$payload->pull_request->assignee->login}</a>\n";
}

$message .= require __DIR__ . '/partials/_reviewers.php';

$message .= require __DIR__ . '/partials/_body.php';

echo $message;
14 changes: 14 additions & 0 deletions resources/events/pull_request/opened.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,17 @@
/**
* @var $payload mixed
*/

$message = "👷‍♂️🛠️ <b>New Pull Request</b> - <a href=\"{$payload->pull_request->html_url}\">{$payload->repository->full_name}#{$payload->pull_request->number}</a> create by <a href=\"{$payload->pull_request->user->html_url}\">@{$payload->pull_request->user->login}</a>\n\n";

$message .= "🛠 <b>{$payload->pull_request->title}</b> \n\n";

if (isset($payload->pull_request->assignee)) {
$message .= "🙋 Assignee: <a href=\"{$payload->pull_request->assignee->html_url}\">@{$payload->pull_request->assignee->login}</a>\n";
}

$message .= require __DIR__ . '/partials/_reviewers.php';

$message .= require __DIR__ . '/partials/_body.php';

echo $message;
14 changes: 14 additions & 0 deletions resources/events/pull_request/partials/_body.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* @var $payload mixed
*/

if (!empty($payload->pull_request->body)) {
$body = $payload->pull_request->body;
if (strlen($body) > 50) {
$body = substr($body, 0, 50) . '...';
}
return "📖 <b>Body:</b>\n{$body}";
}

return "";
16 changes: 16 additions & 0 deletions resources/events/pull_request/partials/_reviewers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* @var $payload mixed
*/

$message = '';
if (count($payload->pull_request->requested_reviewers) > 0) {
$reviewers = [];
foreach ($payload->pull_request->requested_reviewers as $reviewer) {
$reviewers[] = $reviewer->login;
}

$message .= "👥 Reviewers: " . implode(', ', $reviewers) . "\n";
}

return $message;
18 changes: 18 additions & 0 deletions resources/events/pull_request/reopened.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* @var $payload mixed
*/

$message = "👷‍♂️🛠️ <b>Reopened Pull Request</b> - <a href=\"{$payload->pull_request->html_url}\">{$payload->repository->full_name}#{$payload->pull_request->number}</a> by <a href=\"{$payload->pull_request->user->html_url}\">@{$payload->pull_request->user->login}</a>\n\n";

$message .= "🛠 <b>{$payload->pull_request->title}</b> \n\n";

if (isset($payload->pull_request->assignee)) {
$message .= "🙋 Assignee: <a href=\"{$payload->pull_request->assignee->html_url}\">@{$payload->pull_request->assignee->login}</a>\n";
}

$message .= require __DIR__ . '/partials/_reviewers.php';

$message .= require __DIR__ . '/partials/_body.php';

echo $message;
4 changes: 2 additions & 2 deletions resources/events/workflow_run/completed.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

$message .= "Done workflow: 🎉 <b>{$payload->workflow_run->name}</b> ✨ \n\n";

$message .= "📤 Commit: <b>{$payload->workflow_run->head_commit->message}</b>\n";
$message .= "📤 Commit: <b>{$payload->workflow_run->head_commit->message}</b>\n\n";

$message .= "🔗 Link: <a href=\"{$payload->workflow_run->html_url}\">{$payload->workflow_run->runner_id}</a>\n\n";
$message .= "🔗 Link: <a href=\"{$payload->workflow_run->html_url}\">{$payload->workflow_run->html_url}</a>\n\n";

echo $message;
4 changes: 2 additions & 2 deletions resources/events/workflow_run/requested.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

$message .= "Running workflow: 💥 <b>{$payload->workflow_run->name}</b> ⏳\n\n";

$message .= "📤 Commit: <b>{$payload->workflow_run->head_commit->message}</b>\n";
$message .= "📤 Commit: <b>{$payload->workflow_run->head_commit->message}</b>\n\n";

$message .= "🔗 Link: <a href=\"{$payload->workflow_run->html_url}\">{$payload->workflow_run->runner_id}</a>\n\n";
$message .= "🔗 Link: <a href=\"{$payload->workflow_run->html_url}\">{$payload->workflow_run->html_url}</a>\n\n";

echo $message;
3 changes: 3 additions & 0 deletions resources/tools/about.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Thanks for using our bot.

The bot is designed to send notifications based on GitHub events from your github repo instantly to your Telegram account.
8 changes: 8 additions & 0 deletions resources/tools/help.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<b>Available Commands </b>

/id - To get chat id.
/host - To get Host Address.
/help - To show this Message.
/usage - How to use me.

Select a command :
1 change: 1 addition & 0 deletions resources/tools/host.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Server Address : <a href="<?= $_SERVER['REMOTE_ADDR'] ?>"><?= $_SERVER['REMOTE_ADDR'] ?></a>
11 changes: 11 additions & 0 deletions resources/tools/start.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
* @var $first_name string
*/

?>
<b>🙋🏻 <?= config('app.name') ?> 🤓</b>

Hey <b><?= $first_name ?></b>,

I can send you notifications from your GitHub Repository instantly to your Telegram. use /help for more information about me.
8 changes: 8 additions & 0 deletions resources/tools/usage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<b>Adding webhook (Website Address) to your GitHub repository</b>

1) Redirect to <i>Repository Settings->Webhook->Add Webhook</i>.
2) Set your Payload URL.
3) Set content type to "<code>application/x-www-form-urlencoded</code>"
4) Choose events would you like to trigger in this webhook.

<b>That it. you will receive all notifications through me 🤗</b>
14 changes: 7 additions & 7 deletions src/Services/TelegramService.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public function telegramToolHandler(string $text = null): void
{
switch ($text) {
case '/start':
;
$reply = "<b>🙋🏻 " . config('app.name')
. " 🤓</b>\n\nHey <b>{$this->telegram->FirstName()}</b>,\n\nI can send you notifications from your GitHub Repository instantly to your Telegram. use /help for more information about me.";
$reply = get_tool_template('start', [
'first_name' => $this->telegram->FirstName()
]);
$content = array(
'chat_id' => $this->chatId,
'photo' => curl_file_create('public/images/github.jpeg', 'image/png'),
Expand All @@ -90,7 +90,7 @@ public function telegramToolHandler(string $text = null): void
),
]
];
$reply = "<b>Available Commands </b>\n\n/id - To get chat id.\n/host - To get Host Address.\n/help - To show this Message.\n/usage - How to use me.\n\nSelect a command :";
$reply = get_tool_template('help');
$content = array(
'chat_id' => $this->chatId,
'reply_markup' => $this->telegram->buildInlineKeyBoard($option),
Expand All @@ -113,7 +113,7 @@ public function telegramToolHandler(string $text = null): void

break;
case '/host':
$reply = "Server Address : <a href=\"{$_SERVER['REMOTE_ADDR']}\">{$_SERVER['REMOTE_ADDR']}</a>";
$reply = get_tool_template('host');
$content = array(
'chat_id' => $this->chatId,
'text' => $reply,
Expand All @@ -124,7 +124,7 @@ public function telegramToolHandler(string $text = null): void

break;
case '/usage':
$reply = "<b>Adding webhook (Website Address) to your GitHub repository</b>\n\n 1) Redirect to <i>Repository Settings->Webhook->Add Webhook</i>. \n 2) Set your Payload URL.\n 3) Set content type to \"<code>application/x-www-form-urlencoded</code>\"\n 4) Choose events would you like to trigger in this webhook.\n\n <b>That it. you will receive all notifications through me 🤗</b>";
$reply = get_tool_template('usage');
$content = array(
'chat_id' => $this->chatId,
'text' => $reply,
Expand All @@ -151,7 +151,7 @@ public function telegramToolHandler(string $text = null): void
protected function sendCallbackResponse(string $callback = null): void
{
if (!empty($callback) && $callback == 'about') {
$reply = "Thanks for using our bot.\n\nThe bot is designed to send notifications based on GitHub events from your github repo instantly to your Telegram account.";
$reply = get_tool_template('about');
$content = array(
'callback_query_id' => $this->telegram->Callback_ID(),
'text' => $reply,
Expand Down

0 comments on commit 5d7b49e

Please sign in to comment.