Skip to content

Commit

Permalink
Add gtxmessaging Notification Support (#4481)
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Fichtmüller <[email protected]>
Co-authored-by: Frank Elsinga <[email protected]>
  • Loading branch information
cfichtmueller and CommanderStorm authored Mar 26, 2024
1 parent e927327 commit 49b6dac
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 4 deletions.
33 changes: 33 additions & 0 deletions server/notification-providers/gtx-messaging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");

class GtxMessaging extends NotificationProvider {
name = "gtxmessaging";

/**
* @inheritDoc
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";

// The UP/DOWN symbols will be replaced with `???` by gtx-messaging
const text = msg.replaceAll("🔴 ", "").replaceAll("✅ ", "");

try {
const data = new URLSearchParams();
data.append("from", notification.gtxMessagingFrom.trim());
data.append("to", notification.gtxMessagingTo.trim());
data.append("text", text);

const url = `https://rest.gtx-messaging.net/smsc/sendsms/${notification.gtxMessagingApiKey}/json`;

await axios.post(url, data);

return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}

module.exports = GtxMessaging;
4 changes: 3 additions & 1 deletion server/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const GoAlert = require("./notification-providers/goalert");
const SMSManager = require("./notification-providers/smsmanager");
const ServerChan = require("./notification-providers/serverchan");
const ZohoCliq = require("./notification-providers/zoho-cliq");
const GtxMessaging = require("./notification-providers/gtx-messaging");

class Notification {

Expand Down Expand Up @@ -126,7 +127,8 @@ class Notification {
new Webhook(),
new WeCom(),
new GoAlert(),
new ZohoCliq()
new ZohoCliq(),
new GtxMessaging(),
];
for (let item of list) {
if (! item.name) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/NotificationDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ export default {
"Splunk": "Splunk",
"webhook": "Webhook",
"GoAlert": "GoAlert",
"ZohoCliq": "ZohoCliq"
"ZohoCliq": "ZohoCliq",
"gtxmessaging": "GtxMessaging"
};
// Put notifications here if it's not supported in most regions or its documentation is not in English
Expand Down
49 changes: 49 additions & 0 deletions src/components/notifications/GtxMessaging.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div class="mb-3">
<label for="gtxmessaging-api-key" class="form-label">{{ $t("API Key") }}</label>
<HiddenInput id="gtxmessaging-api-key" v-model="$parent.notification.gtxMessagingApiKey" :required="true"></HiddenInput>
<div class="form-text">
{{ $t("gtxMessagingApiKeyHint") }}
</div>
</div>
<div class="mb-3">
<label for="gtxmessaging-from" class="form-label">{{ $t("From Phone Number / Transmission Path Originating Address (TPOA)") }}</label>
<input id="gtxmessaging-from" v-model="$parent.notification.gtxMessagingFrom" type="text" class="form-control" required>
<i18n-t tag="div" keypath="gtxMessagingFromHint" class="form-text">
<template #e164>
<a href="https://wikipedia.org/wiki/E.164">E.164</a>
</template>
<template #e212>
<a href="https://wikipedia.org/wiki/E.212">E.212</a>
</template>
<template #e214>
<a href="https://wikipedia.org/wiki/E.214">E.214</a>
</template>
</i18n-t>
</div>
<div class="mb-3">
<label for="gtxmessaging-to" class="form-label">{{ $t("To Phone Number") }}</label>
<input id="gtxmessaging-to" v-model="$parent.notification.gtxMessagingTo" type="text" pattern="^\+\d+$" class="form-control" required>
<i18n-t tag="div" keypath="gtxMessagingToHint" class="form-text">
<template #e164>
<a href="https://wikipedia.org/wiki/E.164">E.164</a>
</template>
<template #e212>
<a href="https://wikipedia.org/wiki/E.212">E.212</a>
</template>
<template #e214>
<a href="https://wikipedia.org/wiki/E.214">E.214</a>
</template>
</i18n-t>
</div>
</template>

<script>
import HiddenInput from "../HiddenInput.vue";
export default {
components: {
HiddenInput
}
};
</script>
4 changes: 3 additions & 1 deletion src/components/notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import GoogleChat from "./GoogleChat.vue";
import Gorush from "./Gorush.vue";
import Gotify from "./Gotify.vue";
import GrafanaOncall from "./GrafanaOncall.vue";
import GtxMessaging from "./GtxMessaging.vue";
import HomeAssistant from "./HomeAssistant.vue";
import HeiiOnCall from "./HeiiOnCall.vue";
import Kook from "./Kook.vue";
Expand Down Expand Up @@ -113,7 +114,8 @@ const NotificationFormList = {
"WeCom": WeCom,
"GoAlert": GoAlert,
"ServerChan": ServerChan,
"ZohoCliq": ZohoCliq
"ZohoCliq": ZohoCliq,
"gtxmessaging": GtxMessaging,
};

export default NotificationFormList;
7 changes: 6 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -887,5 +887,10 @@
"Browser Screenshot": "Browser Screenshot",
"What is a Remote Browser?": "What is a Remote Browser?",
"wayToGetHeiiOnCallDetails": "How to get the Trigger ID and API Keys is explained in the {documentation}",
"documentationOf": "{0} Documentation"
"documentationOf": "{0} Documentation",
"gtxMessagingApiKeyHint": "You can find your API key at: My Routing Accounts > Show Account Information > API Credentials > REST API (v2.x)",
"From Phone Number / Transmission Path Originating Address (TPOA)": "From Phone Number / Transmission Path Originating Address (TPOA)",
"gtxMessagingFromHint": "On mobile phones, your recipients sees the TPOA displayed as the sender of the message. Allowed are up to 11 alphanumeric characters, a shortcode, the local longcode or international numbers ({e164}, {e212} or {e214})",
"To Phone Number": "To Phone Number",
"gtxMessagingToHint": "International format, with leading \"+\" ({e164}, {e212} or {e214})"
}

0 comments on commit 49b6dac

Please sign in to comment.