Added format field to Telegram Messages (#9404)

* Add format field to Telegram Messages

Added Telegram field to send formatted messages as Mardown or HTML

* Update Telegram.php

* Correct Mistypo.

* Correct mistypo

* Correct Mistypo

* Correct mistypo

* Update Transports.md

* Add Format field on Telegram Examples

* Change Telegram Format field to type select

* Add "blank" option to Format field

* Update Telegram.php

* Update Telegram.php

* Update Telegram.php
This commit is contained in:
Paulo Coimbra
2018-11-08 19:26:29 -03:00
committed by Neil Lathwood
parent 31dfc1fad7
commit 518e5f06d3
2 changed files with 19 additions and 1 deletions

View File

@ -35,6 +35,7 @@ class Telegram extends Transport
}
$telegram_opts['chat_id'] = $this->config['telegram-chat-id'];
$telegram_opts['token'] = $this->config['telegram-token'];
$telegram_opts['format'] = $this->config['telegram-format'];
return $this->contactTelegram($obj, $telegram_opts);
}
@ -51,7 +52,11 @@ class Telegram extends Transport
$curl = curl_init();
set_curl_proxy($curl);
$text = urlencode($obj['msg']);
curl_setopt($curl, CURLOPT_URL, ("https://api.telegram.org/bot{$data['token']}/sendMessage?chat_id={$data['chat_id']}&text=$text"));
$format="";
if ($data['format']) {
$format="&parse_mode=" . $data['format'];
}
curl_setopt($curl, CURLOPT_URL, ("https://api.telegram.org/bot{$data['token']}/sendMessage?chat_id={$data['chat_id']}&text=$text{$format}"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
@ -79,11 +84,23 @@ class Telegram extends Transport
'name' => 'telegram-token',
'descr' => 'Telegram Token',
'type' => 'text',
],
[
'title' => 'Format',
'name' => 'telegram-format',
'descr' => 'Telegram format',
'type' => 'select',
'options' => [
'' => '',
'Markdown' => 'Markdown',
'HTML' => 'HTML'
]
]
],
'validation' => [
'telegram-chat-id' => 'required|string',
'telegram-token' => 'required|string',
'telegram-format' => 'string',
]
];
}

View File

@ -435,6 +435,7 @@ Click on 'Add Telegram config' and put your chat id and token into the relevant
| ------ | ------- |
| Chat ID | 34243432 |
| Token | 3ed32wwf235234 |
| Format | HTML or MARKDOWN |
## Twilio SMS