Files
crm.clientright.ru/modules/SMSNotifier/providers/telegram.php
Fedor ac7467f0b4 Major CRM updates: AI Assistant, Court Status API, S3 integration improvements, and extensive file storage system
- Added comprehensive AI Assistant system (aiassist/ directory):
  * Vector search and embedding capabilities
  * Typebot proxy integration
  * Elastic search functionality
  * Message classification and chat history
  * MCP proxy for external integrations

- Implemented Court Status API (GetCourtStatus.php):
  * Real-time court document status checking
  * Integration with external court systems
  * Comprehensive error handling and logging

- Enhanced S3 integration:
  * Improved file backup system with metadata
  * Batch processing capabilities
  * Enhanced error logging and recovery
  * Copy operations with URL fixing

- Added Telegram contact creation API
- Improved error logging across all modules
- Enhanced callback system for AI responses
- Extensive backup file storage with timestamps
- Updated documentation and README files

- File storage improvements:
  * Thousands of backup files with proper metadata
  * Fix operations for broken file references
  * Project-specific backup and recovery systems
  * Comprehensive file integrity checking

Total: 26,461+ files added/modified including AWS SDK, vendor dependencies, and extensive backup system.
2025-10-16 11:17:21 +03:00

136 lines
4.5 KiB
PHP

<?php
/*********************************************************************************
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved. /modules/SMSNotifier/providers/telegram.php
*********************************************************************************
* copy this lines at /var/www/html/vrm/modules/SMSNotifier/providers/telegram.php
* chown to apache user like the other files inside this dir
* then chose this provider at vtiger SMSNotifier settings
* SET [USERNAME], [PASSWORD] AND [FROM] ALL = 0 at SMSNotifier provider settings
* Insert your telegram bot token at line 62
* Send the message as SMS
* Telegram version edited by George Rousopoulos
* CC BY 4.0)- https://creativecommons.org/licenses/by/4.0/deed
* ********************************************************************************/
class SMSNotifier_telegram_Provider implements SMSNotifier_ISMSProvider_Model {
private $_username;
private $_password;
private $_parameters = array();
const SERVICE_URI = 'https://api.telegram.org/';
private static $REQUIRED_PARAMETERS = array('from');
function __construct() {
}
public function getName() {
return 'telegram';
}
public function setAuthParameters($username, $password) {
$this->_username = $username;
$this->_password = $password;
}
public function setParameter($key, $value) {
$this->_parameters[$key] = $value;
}
public function getParameter($key, $defvalue = false) {
if (isset($this->_parameters[$key])) {
return $this->_parameters[$key];
}
return $defvalue;
}
public function getRequiredParams() {
return self::$REQUIRED_PARAMETERS;
}
public function getServiceURL($type = false) {
if ($type) {
switch (strtoupper($type)) {
case self::SERVICE_AUTH : return self::SERVICE_URI . '';
case self::SERVICE_SEND : return self::SERVICE_URI . 'bot'.'6118440594:AAGpqeudXF9wHSZ7vpAsXQ4Jp5XXlUoqB1A'.'/sendMessage';
case self::SERVICE_QUERY : return self::SERVICE_URI . '';
}
}
return false;
}
protected function prepareParameters() {
$params = array('username' => $this->_username, 'password' => $this->_password);
foreach (self::$REQUIRED_PARAMETERS as $key) {
$params[$key] = $this->getParameter($key);
}
return $params;
}
public function send($message, $tonumbers) {
if (!is_array($tonumbers)) {
$tonumbers = array($tonumbers);
}
//foreach ($tonumbers as $i => $tonumber) {
// $tonumbers[$i] = str_replace(array('(', ')', ' ', '+', '-'), '', $tonumber);
//}
foreach($tonumbers as $tonumbers) {
$message = implode("\r\n", explode('\r\n', $message)); //line braker for telegram
$params = $this->prepareParameters();
$params['text'] = $message;
$params['chat_id'] = $tonumbers;
$serviceURL = $this->getServiceURL(self::SERVICE_SEND);
$httpClient = new Vtiger_Net_Client($serviceURL);
$messageId = $httpClient->doGet($params);
$queryResult = $this->query($messageId);
$result = array(
'id' => $messageId,
'status' => $queryResult['status'],
'error' => false
);
if ($queryResult['status'] == self::MSG_STATUS_FAILED) {
$result['error'] = true;
}
$results = array();
foreach ($tonumbers as $i => $tonumber) {
$results[$i] = $result;
$results[$i]['chat_id'] = $tonumber;
}
}
return $results;
}
public function query($messageid) {
$params = array('username' => $this->_username, 'password' => $this->_password, 'msgid' => $messageid);
$serviceURL = $this->getServiceURL(self::SERVICE_QUERY);
$httpClient = new Vtiger_Net_Client($serviceURL);
$response = $httpClient->doGet($params);
$result = array();
if (stripos($response, 'Delivered') !== false) {
$result['status'] = self::MSG_STATUS_DISPATCHED;
$result['needlookup'] = 0;
$result['statusmessage'] = 'Message delivered';
} else if (stripos($response, 'Submitted') !== false) {
$result['status'] = self::MSG_STATUS_PROCESSING;
$result['needlookup'] = 1;
$result['statusmessage'] = 'Message submitted for processing';
} else {
$result['status'] = self::MSG_STATUS_FAILED;
$result['needlookup'] = 0;
$result['statusmessage'] = 'Message delivery failed.';
}
return $result;
}
}
?>