feat(notif): include poster image in Telegram notifications (#1112)

This commit is contained in:
TheCatLady
2021-03-08 14:22:03 -05:00
committed by GitHub
parent 1a7dc1acf5
commit 48387e5b2f

View File

@@ -4,13 +4,21 @@ import logger from '../../../logger';
import { getSettings, NotificationAgentTelegram } from '../../settings'; import { getSettings, NotificationAgentTelegram } from '../../settings';
import { BaseAgent, NotificationAgent, NotificationPayload } from './agent'; import { BaseAgent, NotificationAgent, NotificationPayload } from './agent';
interface TelegramPayload { interface TelegramMessagePayload {
text: string; text: string;
parse_mode: string; parse_mode: string;
chat_id: string; chat_id: string;
disable_notification: boolean; disable_notification: boolean;
} }
interface TelegramPhotoPayload {
photo: string;
caption: string;
parse_mode: string;
chat_id: string;
disable_notification: boolean;
}
class TelegramAgent class TelegramAgent
extends BaseAgent<NotificationAgentTelegram> extends BaseAgent<NotificationAgentTelegram>
implements NotificationAgent { implements NotificationAgent {
@@ -125,14 +133,22 @@ class TelegramAgent
try { try {
const endpoint = `${this.baseUrl}bot${ const endpoint = `${this.baseUrl}bot${
this.getSettings().options.botAPI this.getSettings().options.botAPI
}/sendMessage`; }/${payload.image ? 'sendPhoto' : 'sendMessage'}`;
await axios.post(endpoint, { await (payload.image
? axios.post(endpoint, {
photo: payload.image,
caption: this.buildMessage(type, payload),
parse_mode: 'MarkdownV2',
chat_id: `${this.getSettings().options.chatId}`,
disable_notification: this.getSettings().options.sendSilently,
} as TelegramPhotoPayload)
: axios.post(endpoint, {
text: this.buildMessage(type, payload), text: this.buildMessage(type, payload),
parse_mode: 'MarkdownV2', parse_mode: 'MarkdownV2',
chat_id: `${this.getSettings().options.chatId}`, chat_id: `${this.getSettings().options.chatId}`,
disable_notification: this.getSettings().options.sendSilently, disable_notification: this.getSettings().options.sendSilently,
} as TelegramPayload); } as TelegramMessagePayload));
if ( if (
payload.notifyUser.settings?.enableNotifications && payload.notifyUser.settings?.enableNotifications &&
@@ -140,13 +156,22 @@ class TelegramAgent
payload.notifyUser.settings?.telegramChatId !== payload.notifyUser.settings?.telegramChatId !==
this.getSettings().options.chatId this.getSettings().options.chatId
) { ) {
await axios.post(endpoint, { await (payload.image
? axios.post(endpoint, {
photo: payload.image,
caption: this.buildMessage(type, payload),
parse_mode: 'MarkdownV2',
chat_id: `${payload.notifyUser.settings.telegramChatId}`,
disable_notification:
payload.notifyUser.settings.telegramSendSilently,
} as TelegramPhotoPayload)
: axios.post(endpoint, {
text: this.buildMessage(type, payload), text: this.buildMessage(type, payload),
parse_mode: 'MarkdownV2', parse_mode: 'MarkdownV2',
chat_id: `${payload.notifyUser.settings.telegramChatId}`, chat_id: `${payload.notifyUser.settings.telegramChatId}`,
disable_notification: disable_notification:
payload.notifyUser.settings.telegramSendSilently, payload.notifyUser.settings.telegramSendSilently,
} as TelegramPayload); } as TelegramMessagePayload));
} }
return true; return true;