First working version.
This commit is contained in:
24
src/salvium_tipbot_common.php
Normal file
24
src/salvium_tipbot_common.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
function sendMessage(int $chatId, string $text, array $options = []): void {
|
||||
global $config;
|
||||
$url = "https://api.telegram.org/bot{$config['TELEGRAM_BOT_TOKEN']}/sendMessage";
|
||||
$payload = array_merge(['chat_id' => $chatId, 'text' => $text], $options);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
|
||||
if (!empty($config['IPV4_ONLY'])) {
|
||||
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
}
|
||||
curl_exec($ch);
|
||||
curl_close($ch);
|
||||
}
|
||||
|
||||
function isValidSalviumAddress(string $address): bool {
|
||||
// Accepts standard and subaddress prefixes for Salvium (e.g. SaLvd, SaLvs)
|
||||
return preg_match('/^SaLv[a-zA-Z0-9]{95}$/', $address) === 1;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user