View ProjeQtOr On SourceForge.net
ProjeQtOr - Project Management Tool
Support us on Capterra
OIN - Open Invention Network
ProjeQtOr free project management software - New Telegram Bot Plugin - ProjeQtOr
 
 

New Telegram Bot Plugin

More
06 Mar 2021 08:49 #1 by Baryhobal
Good morning, or good evening

For the last 3-4 weeks, I've been tinkering a bit with projeqtor for my brother. He wanted some new features so I had a go.One of them was a way to send notifications to users in a better way than mails. Indeed, he didn't really like the idea of receiving several emails for simple notifications such a ticket's state change. So I added a few lines to the "SqlElement.php" file so that, when sending mails, it first checks if the person has a custom field containing their Telegram id, and if so, sends the notification via Telegram.

However, I know that it won't be easy to maitain this feature trhough the future versions since I modified one of the main files, so I was wandering if it was possible to make it as a plugin. I've attached the modified file (for projeqtor v9.0.5). I've also used node-red to manage the bot in order to redirect new messages to a script (also attached as "telegram_bot.php").

Configuration:
  • First, add two custom fields to the Resource class: an "idTelegram" field (varchar) to store the telegram id (like "@ARandomId") and a chatIdTelegram field (varchar). Both need to be visible and you can put chatIdTelegram as readonly.
  • In SqlElement.php: You just need to replace "YOUR_URL" with the url of your server and "YOUR_BOT_TOKEN" with your Telegram bot token.
  • In telegram_bot.php: You need to replace "USER:PWD" with a valid projeqtor user and password, "YOUR_API_KEY" with the corresponding API key, "YOUR_URL" with the url of your server and "YOUR_BOT_TOKEN" with your Telegram bot token.
You can also change the message at the end of "telegram_bot.php" in the $msg variable (I wrote them in french sry).

Does this seem to be a good enough idea to make it a plugin ?

Anyway, I hope this will help others and maybe reach your interest
Attachments:

Please Log in or Create an account to join the conversation.

More
06 Mar 2021 10:39 #2 by babynus
Replied by babynus on topic New Telegram Bot Plugin
Hi,

Your idea is interesting, replacing emails with chat interface.
I had a look at your code, and there are few things that will have to be improved :
  • parametering of all parameters you defined as Strings.
    Trick : you can add in parameters.php
    $myParameter='YOUR_PARAMETER';
    then use is projeqtor code
    Parameter::getGlobalParameter('myParameter');
    We'll then just have to "move" the parameters from file to DB to intergate it, and possibly change it as user parameter...
  • translation of messages (we do not accept hard coded messages, with only exception in technical log writing in english)
  • why restrict to Telegram ?
    I understand reasons that let you prefer Telegram to other chats, but I think this could be easily extended to many other chats, such as Whatsapp, Messenger, Discord, ..
Also it is difficult to imagine this as a plugin, but possibly it could be included in community version.
It's too late for V9.1 that is under testing before soon deployment, but we'll have a look at this for V9.2.
I recorded Ticket #5359.

Babynus
Administrator of ProjeQtOr web site

Please Log in or Create an account to join the conversation.

More
06 Mar 2021 10:57 #3 by Baryhobal
Replied by Baryhobal on topic New Telegram Bot Plugin
Thank you very much !

Of course parametering would be a necessity if it were to become a full feature. I went for the easy way by hard-coding the messages cause it was only on a very small scale but I admit it's not optimal.
Concerning other chats, Messenger and Discord would be quite easy to implement but Whatsapp would be a bit tricky I believe since you can't easily make a Whatsapp bot.

Thank you very much for your reply and for considering my idea

Please Log in or Create an account to join the conversation.

More
06 Mar 2021 11:57 - 06 Mar 2021 12:05 #4 by Baryhobal
Replied by Baryhobal on topic New Telegram Bot Plugin
Small correction, the line (in SqlElement.php)
$res = $resource->getSqlElementsFromCriteria ( array("idTelegram"=>str_replace("@tg@", "", $adr)), false );

should be
$res = $resource->getSqlElementsFromCriteria ( array("idTelegram"=>str_replace("@tg", "", $adr)), false );
(without the second "@")

and the line
array_push($tgUsers, $res[0]->chatIdTelegram);

should be
if (!in_array($res[0]->chatIdTelegram, $tgUsers)) {
    array_push($tgUsers, $res[0]->chatIdTelegram);
}
(sry, I've just found out about these problems)
Last edit: 06 Mar 2021 12:05 by Baryhobal.

Please Log in or Create an account to join the conversation.

More
07 Mar 2021 18:10 #5 by Baryhobal
Replied by Baryhobal on topic New Telegram Bot Plugin
Hello again,
I also added the possibility to create templates for the messages. It works exactly the same as email templates. I added a page and copied the email template class (modified so that it doesn't create html but a more suitable message for telegram). Though it's not perfect, it works pretty well !
Don't know if it would be interesting enough to implement it

Please Log in or Create an account to join the conversation.

More
08 Mar 2021 13:59 #6 by babynus
Replied by babynus on topic New Telegram Bot Plugin
Yes, please post your files.
We'll have a look at oppotunity toi integrate it on V9.2

Babynus
Administrator of ProjeQtOr web site

Please Log in or Create an account to join the conversation.

Moderators: babynusprotion
Time to create page: 0.045 seconds

Cookies settings

×

Functional Cookies

Ce site utilise des cookies pour assurer son bon fonctionnement et ne peuvent pas être désactivés de nos systèmes. Nous ne les utilisons pas à des fins publicitaires. Si ces cookies sont bloqués, certaines parties du site ne pourront pas fonctionner.

Session

Please login to see yours activities!

Other cookies

Ce site web utilise un certain nombre de cookies pour gérer, par exemple, les sessions utilisateurs.