mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Transport Messagebird voice message API (#15115)
* Messagebird voice message API * Reverse permission change on rrd/.gitignore * Name string
This commit is contained in:
@@ -41,6 +41,7 @@ class Messagebird extends Transport
|
||||
public function deliverAlert(array $alert_data): bool
|
||||
{
|
||||
$messagebird_msg = mb_strimwidth($alert_data['msg'], 0, $this->config['messagebird-limit'] - 3, '...');
|
||||
$api_url = 'https://rest.messagebird.com/messages';
|
||||
$fields = [
|
||||
'recipients' => $this->config['messagebird-recipient'],
|
||||
'originator' => $this->config['messagebird-origin'],
|
||||
@@ -51,7 +52,7 @@ class Messagebird extends Transport
|
||||
->withHeaders([
|
||||
'Authorization' => 'AccessKey ' . $this->config['messagebird-key'],
|
||||
])
|
||||
->post($this->config['messagebird-url'], $fields);
|
||||
->post($api_url, $fields);
|
||||
|
||||
if ($res->successful() && $res->status() == '201') {
|
||||
return true;
|
||||
@@ -64,13 +65,6 @@ class Messagebird extends Transport
|
||||
{
|
||||
return [
|
||||
'config' => [
|
||||
[
|
||||
'title' => 'Messagebird API URL',
|
||||
'name' => 'messagebird-url',
|
||||
'descr' => 'Messagebird API URL',
|
||||
'type' => 'text',
|
||||
'default' => 'https://rest.messagebird.com/messages',
|
||||
],
|
||||
[
|
||||
'title' => 'Messagebird API key',
|
||||
'name' => 'messagebird-key',
|
||||
@@ -98,7 +92,6 @@ class Messagebird extends Transport
|
||||
],
|
||||
],
|
||||
'validation' => [
|
||||
'messagebird-url' => 'required|url',
|
||||
'messagebird-key' => 'required',
|
||||
'messagebird-origin' => 'required',
|
||||
'messagebird-recipient' => 'required',
|
||||
|
159
LibreNMS/Alert/Transport/Messagebirdvoice.php
Normal file
159
LibreNMS/Alert/Transport/Messagebirdvoice.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
* Messagebirdvoice.php
|
||||
*
|
||||
* LibreNMS Messagebird voice API Tranport
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @link https://www.librenms.org
|
||||
*
|
||||
* @copyright 2023 Sjef van Zeeland
|
||||
* @author https://github.com/jepke/
|
||||
*
|
||||
* Messagebird voice will return 201 status if the call was initiated, if status is not 201 LibreNMS will log the full error
|
||||
*
|
||||
* @contributer f0o, sdef2
|
||||
* Thanks to F0o <f0o@devilcode.org> for creating the Slack transport which is the majority of this code.
|
||||
* Thanks to sdef2 for figuring out the differences needed to make Discord work.
|
||||
* Thanks to theherodied for discord transport used as a base for messagebird.
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Alert\Transport;
|
||||
use LibreNMS\Exceptions\AlertTransportDeliveryException;
|
||||
use LibreNMS\Util\Http;
|
||||
|
||||
class Messagebirdvoice extends Transport
|
||||
{
|
||||
protected string $name = 'Messagebird Voice';
|
||||
|
||||
public function deliverAlert(array $alert_data): bool
|
||||
{
|
||||
$messagebird_msg = mb_strimwidth($alert_data['msg'], 0, 1000, '...');
|
||||
$api_url = 'https://rest.messagebird.com/voicemessages';
|
||||
$fields = [
|
||||
'recipients' => $this->config['messagebird-recipient'],
|
||||
'originator' => $this->config['messagebird-origin'],
|
||||
'language' => $this->config['messagebird-language'],
|
||||
'voice' => $this->config['messagebird-voice'],
|
||||
'body' => $messagebird_msg,
|
||||
];
|
||||
|
||||
$res = Http::client()
|
||||
->withHeaders([
|
||||
'Authorization' => 'AccessKey ' . $this->config['messagebird-key'],
|
||||
])
|
||||
->post($api_url, $fields);
|
||||
if ($res->successful() && $res->status() == '201') {
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new AlertTransportDeliveryException($alert_data, $res->status(), $res->body(), $messagebird_msg, $fields);
|
||||
}
|
||||
|
||||
public static function configTemplate(): array
|
||||
{
|
||||
return [
|
||||
'config' => [
|
||||
[
|
||||
'title' => 'Messagebird API key',
|
||||
'name' => 'messagebird-key',
|
||||
'descr' => 'Messagebird API REST key',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'title' => 'Messagebird originator',
|
||||
'name' => 'messagebird-origin',
|
||||
'descr' => 'Originator in E.164 format eg. +1555###****',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'title' => 'Messagebird recipients',
|
||||
'name' => 'messagebird-recipient',
|
||||
'descr' => 'Recipient in E.164 format eg. +1555###****',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'title' => 'Language',
|
||||
'name' => 'messagebird-language',
|
||||
'descr' => 'Spoken Language',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'Welsch' => 'cy-gb',
|
||||
'Danish' => 'da-dk',
|
||||
'German' => 'de-de',
|
||||
'Greek' => 'el-gr',
|
||||
'English (Australia)' => 'en-au',
|
||||
'English (UK)' => 'en-gb',
|
||||
'English (Welsch)' => 'en-gb-wls',
|
||||
'English (India)' => 'en-in',
|
||||
'English (US)' => 'en-us',
|
||||
'Spanish' => 'es-es',
|
||||
'Spanish (Mexico)' => 'es-mx',
|
||||
'Spanish (US)' => 'es-us',
|
||||
'French (Quebec)' => 'fr-ca',
|
||||
'French' => 'fr-fr',
|
||||
'Indonesian' => 'id-id',
|
||||
'Icelandic' => 'is-is',
|
||||
'Italian' => 'it-it',
|
||||
'Japanese' => 'ja-jp',
|
||||
'Korean' => 'ko-kr',
|
||||
'Malay' => 'ms-my',
|
||||
'Norwegian' => 'nb-no',
|
||||
'Dutch' => 'nl-nl',
|
||||
'Polish' => 'pl-pl',
|
||||
'Portuguese (Brazil)' => 'pt-br',
|
||||
'Portuguese' => 'pt-pt',
|
||||
'Romanian' => 'ro-ro',
|
||||
'Russian' => 'ru-ru',
|
||||
'Swedish' => 'sv-se',
|
||||
'Tamil' => 'ta-in',
|
||||
'Thai' => 'th-th',
|
||||
'Turkish' => 'tr-tr',
|
||||
'Vietnamese' => 'vi-vn',
|
||||
'Chinese (Simplified)' => 'zh-cn',
|
||||
'Chinese (HongKong)' => 'zh-hk',
|
||||
],
|
||||
'default' => 'en-us',
|
||||
],
|
||||
[
|
||||
'title' => 'Voice',
|
||||
'name' => 'messagebird-voice',
|
||||
'descr' => 'Male,Female',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
'Female' => 'female',
|
||||
'Male' => 'male',
|
||||
],
|
||||
],
|
||||
[
|
||||
'title' => 'Message repeat',
|
||||
'name' => 'messagebird-repeat',
|
||||
'descr' => 'Number of times the message will be repeated',
|
||||
'type' => 'text',
|
||||
'default' => 1,
|
||||
],
|
||||
],
|
||||
'validation' => [
|
||||
'messagebird-key' => 'required',
|
||||
'messagebird-origin' => 'required',
|
||||
'messagebird-recipient' => 'required',
|
||||
'messagebird-language' => 'in:cy-gb,da-dk,de-de,el-gr,en-au,en-gb,en-gb-wls,en-in,en-us,es-es,es-mx,es-us,fr-ca,fr-fr,id-id,is-is,it-it,ja-jp,ko-kr,ms-my,nb-no,nl-nl,pl-pl,pt-br,pt-pt,ro-ro,ru-ru,sv-se,ta-in,th-th,tr-tr,vi-vn,zh-cn,zh-hk',
|
||||
'messagebird-voice' => 'in:male,female',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
@@ -410,12 +410,24 @@ LibreNMS can send text messages through Messagebird Rest API transport.
|
||||
|
||||
| Config | Example |
|
||||
| ------ | ------- |
|
||||
| Api URL | https://rest.messagebird.com/messages |
|
||||
| Api Key | Api rest key given in the messagebird dashboard |
|
||||
| Originator | E.164 formatted originator |
|
||||
| Recipient | E.164 formatted recipient for multi recipents comma separated |
|
||||
| Character limit | Range 1..480 (max 3 split messages) |
|
||||
|
||||
## Messagebird Voice
|
||||
|
||||
LibreNMS can send messages through Messagebird voice Rest API transport (text to speech).
|
||||
|
||||
| Config | Example |
|
||||
| ------ | ------- |
|
||||
| Api Key | Api rest key given in the messagebird dashboard |
|
||||
| Originator | E.164 formatted originator |
|
||||
| Recipient | E.164 formatted recipient for multi recipents comma separated |
|
||||
| Language | Select box for options |
|
||||
| Spoken voice | Female or Male |
|
||||
| Repeat | X times the message is repeated |
|
||||
|
||||
## Microsoft Teams
|
||||
|
||||
LibreNMS can send alerts to Microsoft Teams [Incoming
|
||||
|
Reference in New Issue
Block a user