foamrider / osticket-telegram

Post notifications from osTicket to Telegram with Telegram Bot
MIT License
31 stars 25 forks source link

is this plugin workin on 1.14 version? #10

Open mhakim168 opened 4 years ago

mhakim168 commented 4 years ago

I've tried enable and put the necessery config, didn't work. any updates?

jaimey commented 4 years ago

Example Telgram Bot URL : https://api.telegram.org/bot1234567:AAEExQ1o9K1w-abcdefghijklmn/

Example Chat ID : @channelname or -12345678

But you get this error:

Content cannot start with the following characters: = - + @

Edit file: include/class.validator.php Search this function

    static function is_formula($text, &$error='') {
        if (!preg_match('/^[^=\+@-].*$/s', $text))
            $error = __('Content cannot start with the following characters: = - + @');
        return $error == '';
    }

Line 223 Remove characters @-

mhakim168 commented 4 years ago

i've tried it, still not forwarding the ticket to my group

arshadsiddique-ctrl commented 4 years ago

I'am also getting this issue with http 502 response in logs. [24-Apr-2020 07:02:46 UTC] Error posting to Telegram. https://api.telegram.org/bot1234567889:ABCDEFGHILOZ-S69djksdfvhfjvdshfv Http code: 502

arshadsiddique-ctrl commented 4 years ago

I came to the conclusion that Telegram has updated their api. I tried to troubleshoot a little bit and it's working for me now.

Screenshot 2020-04-24 at 7 34 55 PM

Telegram Bot URL: https://api.telegram.org/bot{tokenid}>/sendMessage

And in Chat ID: we have to provide another id which will be created dynamically by posting curl for the first time in the group

Eg. curl -s -X POST https://api.telegram.org/bot{tokenid}/sendMessage -F chat_id='{groupchatid}' -F text='test message'

{"ok":false,"error_code":400,"description":"Bad Request: group chat was upgraded to a supergroup chat","parameters":{"migrate_to_chat_id":-10014xxxxxxxx}}

I was able to send messages to my group with below curl request:

curl -s -X POST https://api.telegram.org/bot{tokenid}/sendMessage -F chat_id='-10014xxxxxxxx' -F text='Hi! Arshad'

{"ok":true,"result":{"message_id":3,"from":{"id":1278xxxxx,"is_bot":true,"first_name":"XYZTechBot","username":"XYZTechSupportBot"},"chat":{"id":-10014xxxxxxxx,"title":"XYZTechSupport","type":"supergroup"},"date":1587736181,"text":"Hi! Arshad"}}

Now I am able to receive messages on telegram whenever a new ticket is created. 2020-04-24 20 15 16 (2)

SashkaNebesny commented 4 years ago

Hello. I have such a problem: installed the plugin, registered the necessary settings, activated it. But, when the user clicks the "create request" button, the browser displays the HTTP ERROR 500 error. And in the logs of the web server: [Thu Jun 04 17:59:49.891877 2020] [php7:error] [pid 2875] [client 1*.8.3*.1*2:56871] PHP Fatal error: Uncaught Error: Call to undefined function curl_init() in /var/www/html/include/plugins/telegrambot/telegrambot.php:51\nStack trace:\n#0 /var/www/html/include/plugins/telegrambot/telegrambot.php(38): TelegramPlugin->sendToTelegram(Array)\n#1 /var/www/html/include/class.signal.php(98): TelegramPlugin->onTicketCreated(Object(Ticket), NULL)\n#2 /var/www/html/include/class.ticket.php(4461): Signal::send('ticket.created', Object(Ticket))\n#3 /var/www/html/open.php(42): Ticket::create(Array, Array, 'Web')\n#4 {main}\n\nNext Error: Call to undefined function curl_close() in /var/www/html/include/plugins/telegrambot/telegrambot.php:73\nStack trace:\n#0 /var/www/html/include/plugins/telegrambot/telegrambot.php(38): TelegramPlugin->sendToTelegram(Array)\n#1 /var/www/html/include/class.signal.php(98): TelegramPlugin->onTicketCreated(Object(Ticket), NULL)\n#2 /var/www/html/include/class.ticket.php(4461): Signal::send('ticket.created', Object(Ticket))\n#3 /var/www/html/open.php(42): Ticket::create(Array, Array, 'Web')\n#4 {main}\n thro in /var/www/html/include/plugins/telegrambot/telegrambot.php on line 73, referer: https://helpdesk.*****.ua/open.php OsTicket version v1.14.1 Apache / 2.4.29 web server software (Ubuntu) MySQL version 5.7.30 PHP version 7.2.24-0ubuntu0.18.04.4

arshadsiddique-ctrl commented 4 years ago

@SashkaNebesny Did you installed the curl module for php? sudo apt-get install php7.2-curl

SashkaNebesny commented 4 years ago

Thank! I have another question. Please tell me how to make the bot send messages when there are no subject and Message fields in the application. I understand that this needs to be corrected somewhere here?

{
        global $ost;
        $ticketLink = $ost->getConfig()->getUrl().'scp/tickets.php?id='.$ticket->getId();
        $ticketId = $ticket->getNumber();
        $title = $ticket->getSubject() ?: 'No subject';
        $createdBy = $ticket->getName()." (".$ticket->getEmail().")";
        $chatid = $this->getConfig()->get('telegram-chat-id');
        if ($this->getConfig()->get('telegram-include-body')) {
            $body = $ticket->getLastMessage()->getMessage() ?: 'No content';
            $body = str_replace('<p>', '', $body);
            $body = str_replace('</p>', '<br />' , $body);
            $breaks = array("<br />","<br>","<br/>");
            $body = str_ireplace($breaks, "\n", $body);
            $body = preg_replace('/\v(?:[\v\h]+)/', '', $body);
            $body = strip_tags($body);
        }

If the application does not have these fields, then an error occurs when creating a new ticket: HTTP ERROR 500 error [php7:error] [pid 46603] [client 1*.8.1*.15*:41638] PHP Fatal error: Uncaught Error: Call to a member function getId() on null in /var/www/html/include/client/view.inc.php:145\nStack trace:\n#0 /var/www/html/tickets.php(149): include()\n#1 {main}\n thrown in /var/www/html/include/client/view.inc.php on line 145, referer: https://helpdesk.****.ua/tickets.php?a=edit&id=1067

Pietro-Aretino commented 2 years ago

I've gotten the bot to work to send messages directly to a user, but group chats dont seem to work due to the fact the field wont accept a - sign. Does anyone know how to fix that?