Last active
June 4, 2017 20:21
-
-
Save salvatorecordiano/eb865b4195fc321f167564e33002f133 to your computer and use it in GitHub Desktop.
Codice di esempio associato all'articolo https://www.salvatorecordiano.it/debug-dei-messaggi-di-update-di-un-bot-telegram/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$content = file_get_contents("php://input"); | |
$update = json_decode($content, true); | |
if (! $update) { | |
exit; | |
} | |
$chatId = $update['message']['chat']['id'] ?? null; | |
if ($channelName = $update['channel_post']['chat']['username'] ?? null) { | |
$chatId = sprintf('@%s', $channelName); | |
} | |
if (! $chatId) { | |
exit; | |
} | |
header('Content-Type: application/json'); | |
$dump = json_encode($update, JSON_PRETTY_PRINT); | |
echo json_encode( | |
[ | |
'chat_id' => $chatId, | |
'text' => "```\n$dump\n```", | |
'method' => 'sendMessage', | |
'parse_mode' => 'markdown' | |
] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment