informatica:programacion:php:snippets:telegram
Diferencias
Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previa | ||
| informatica:programacion:php:snippets:telegram [2021/06/23 15:05] – tempwin | informatica:programacion:php:snippets:telegram [2021/11/30 15:05] (actual) – tempwin | ||
|---|---|---|---|
| Línea 9: | Línea 9: | ||
| define(' | define(' | ||
| + | // API de Telegram para realizar el envío del mensaje a través del bot | ||
| $api_url = " | $api_url = " | ||
| Línea 41: | Línea 42: | ||
| </ | </ | ||
| + | <WRAP center round important 60%> | ||
| + | Al usar la sintaxix MarkdownV2 con la API de Telegram, ciertos caracteres [[https:// | ||
| + | </ | ||
| + | |||
| + | |||
| + | Otra opción más portable: | ||
| + | |||
| + | <code php> | ||
| + | // Envía un mensaje a Telegram utilizando su API de bots | ||
| + | // (https:// | ||
| + | function enviar_telegram($id_chat, | ||
| + | |||
| + | // Modo de formato del texto | ||
| + | $parse_mode = " | ||
| + | |||
| + | $data = array( | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ); | ||
| + | |||
| + | if($token_bot != '' | ||
| + | $ch = curl_init(' | ||
| + | curl_setopt_array($ch, | ||
| + | CURLOPT_HEADER | ||
| + | CURLOPT_RETURNTRANSFER => 1, | ||
| + | CURLOPT_POST | ||
| + | CURLOPT_POSTFIELDS | ||
| + | ]); | ||
| + | curl_exec($ch); | ||
| + | curl_close($ch); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | * [[http:// | ||
| + | |||
| + | ==== Escapar caracteres para Markdown ==== | ||
| + | |||
| + | Al usar la sintaxix MarkdownV2 con la API de Telegram, ciertos caracteres [[https:// | ||
| + | |||
| + | <code php> | ||
| + | function escape_message_telegram($mensaje) { | ||
| + | $escaped_message = str_replace( | ||
| + | [' | ||
| + | [' | ||
| + | $mensaje | ||
| + | ); | ||
| + | return $escaped_message; | ||
| + | } | ||
| + | </ | ||
informatica/programacion/php/snippets/telegram.1624453522.txt.gz · Última modificación: por tempwin
