Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/device-login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ export class DeviceLogin {
pendingRedirects.set(reqId, this.onTestVisit(resolve, reject).bind(this));
}),
),
await this.notify(NotificationReason.TEST, url),
await this.notify(NotificationReason.TEST_WITH_URL, url),
await this.notify(NotificationReason.TEST_WITHOUT_URL),
]);
pendingRedirects.delete(reqId);
}
Expand Down Expand Up @@ -175,10 +176,9 @@ export class DeviceLogin {
private async notify(reason: NotificationReason, inUrl?: string): Promise<void> {
let url: string | undefined;
if (inUrl) {
url = inUrl;
if (config.webPortalConfig?.localtunnel) {
url = await getLocaltunnelUrl(inUrl);
} else {
url = inUrl;
}
}
this.L.info({ reason, url }, 'Dispatching notification');
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ export async function redeemAccount(account: AccountConfig): Promise<void> {
}
} catch (e) {
if (e.response) {
if (e.response.body) L.error(e.response.body);
else L.error(e.response);
L.error(e.response.body ?? e.response);
}
L.error(e);
logVersionOnError();
await sendNotification(account.email, NotificationReason.PURCHASE_ERROR);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/notification-reason.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum NotificationReason {
LOGIN = 'LOGIN',
PURCHASE = 'PURCHASE',
CREATE_ACCOUNT = 'CREATE_ACCOUNT',
TEST = 'TEST',
TEST_WITH_URL = 'TEST_WITH_URL',
TEST_WITHOUT_URL = 'TEST_WITHOUT_URL',
PURCHASE_ERROR = 'PURCHASE ERROR',
}
2 changes: 1 addition & 1 deletion src/notifiers/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class DiscordNotifier extends NotifierService {
},
],
title: 'Click to proceed',
url,
...(url ? { url } : {}),
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion src/notifiers/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class EmailNotifier extends NotifierService {
to: this.config.emailRecipientAddress,
subject: `Epic Games free games needs an action performed`,
html: `<p><b>epicgames-freegames-node</b>, reason: ${reason}, account: ${account}.</p>
<p>Link: <a href="${url}">${url}</a></p>`,
${url ? `<p>Link: <a href="${url}">${url}</a></p>` : ''}`,
textEncoding: 'base64', // Some email clients don't like the '=' in the URL when using quoted-printable?
});
L.debug(
Expand Down
19 changes: 12 additions & 7 deletions src/notifiers/gotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,26 @@ export class GotifyNotifier extends NotifierService {
const jsonPayload = {
title: `Epic Games free games needs an action performed`,
/**
* ATTENTION: these are markdown, to make it breaking lines correctly, there is two spaces at the end of line and before the retrun
* ATTENTION: these are markdown; to make lines break correctly, there
* are two spaces at the end of line and before the retrun
*/
message: `* Reason: ${reason}
* Account: ${account}
* URL: [${url}](${url})`,
${url ? `* URL: [${url}](${url})` : ''}`,
priority: this.config.priority,
extras: {
'client::display': {
contentType: 'text/markdown',
},
'client::notification': {
click: {
url,
},
},
...(url
? {
'client::notification': {
click: {
url,
},
},
}
: {}),
},
};

Expand Down
3 changes: 1 addition & 2 deletions src/notifiers/homeassistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export class HomeassistantNotifier extends NotifierService {
title: `Action request from Epic Games`,
message: `epicgames needs an action performed. Reason: ${reason} {{ '\n' -}} Link: ${url}`,
data: {
url,
clickAction: url,
...(url ? { url, clickAction: url } : {}),
...(this.config.customData ?? {}),
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/notifiers/ntfy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export class NtfyNotifier extends NotifierService {
Title: 'epicgames-freegames-node needs an action performed',
Priority: this.config.priority,
Tags: 'closed_lock_with_key',
Click: url,
Authorization: `Bearer ${this.config.token}`,
...(url ? { Click: url } : {}),
},
responseType: 'text',
},
Expand Down
2 changes: 1 addition & 1 deletion src/notifiers/pushover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class PushoverNotifier extends NotifierService {
token: this.config.token,
user: this.config.userKey,
message: `epicgames-freegames-node needs an action performed. Reason: ${reason}`,
url,
...(url ? { url } : {}),
},
{
responseType: 'json',
Expand Down
2 changes: 1 addition & 1 deletion src/notifiers/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class SlackNotifier extends NotifierService {
await axios.post(
this.config.webhookUrl,
{
text: `epicgames-freegames-node needs an action performed. \nReason: ${reason} \nAccount: ${account} \nURL: ${url}`,
text: `epicgames-freegames-node needs an action performed. \nReason: ${reason} \nAccount: ${account}${url ? ` \nURL: ${url}` : ''}`,
},
{
responseType: 'text',
Expand Down
2 changes: 1 addition & 1 deletion src/notifiers/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class WebhookNotifier extends NotifierService {
{
account,
reason,
url,
...(url ? { url } : {}),
},
{
responseType: 'json',
Expand Down