Zabbix-in-Telegram icon indicating copy to clipboard operation
Zabbix-in-Telegram copied to clipboard

You need to mention your bot in 'user' group chat (i.e. type @YourBot)

Open paradoxicalNL opened this issue 6 years ago • 24 comments

So I have worked with this script before - and it worked perfectly!

For some reason, all I get is: 'You need to mention your bot in 'username' group chat (i.e. type @YourBot)'. I (of course) mentioned the bot in the group chat, that did not help. I re-registered the bot, disabled privacy mode, nothing seems to help.. Any ideas what I might be doing wrong, or some recent update to Telegram?

So the steps:

Create bot, fill in API key in zbxtg_settings.py Create a group channel and add bot to it

Test group functionality with '--group' (test without the --group param works):

username@host:/usr/lib/zabbix/alertscripts$ sudo -u zabbix ./zbxtg.py Username "Hi there" "Hi there again" --group
zbxtg.py: You need to mention your bot in 'Username' group chat (i.e. type @YourBot)

paradoxicalNL avatar Aug 10 '17 15:08 paradoxicalNL

@paradoxicalNL , try to kick bot from group and invite it again

ableev avatar Aug 15 '17 17:08 ableev

Kick does not help. I'm able to send message to chat with the curl: curl 'https://api.telegram.org/bot$bot_key/sendMessage?chat_id=$chatid&text=Hello!'

But script always returns mentioned message.

Command line: /usr/share/zabbix/alertscripts/zbxtg.py --group "$chatid" "Test message" "Hello" --debug $chatid is negative integer (e.g. -123456789)

Perlovka avatar Sep 03 '17 05:09 Perlovka

@Perlovka this are no miracles, read README twice, read wiki articles.

ableev avatar Sep 04 '17 09:09 ableev

Yep, there are no miracles. So I did some debug.

  1. Mentioning a bot, that is in privacy mode, in group chat will not appear in getUpdates data. You need to issue a command (something that start with a /).
  2. Treating options ( like --debug) as positional parameters is just a brilliant idea!

Perlovka avatar Sep 04 '17 11:09 Perlovka

So I did some debug.

Nice.

that is in privacy mode

Which privacy mode? In default configuration you need only mention it. Never saw otherwise.

is just a brilliant idea

Idea comes from zabbix rules for custom media scripts, it has no specific API or something.

ableev avatar Sep 04 '17 11:09 ableev

https://core.telegram.org/bots#privacy-mode At least for now, bots by default are in privacy mode, so mentioning a bot (sending @BotName) in a group for some reason will not be reflected in getUpdates api call response, thus the script can't found chat id by it's name. If I send a command to the group, I see message in getUpdates response, with group title and id. I'm not so familiar with telegram, so I just created a bot (https://core.telegram.org/bots#3-how-do-i-create-a-bot) and added it to my group. Nothing special.

Idea comes from zabbix rules for custom media scripts, it has no specific API or something.

Usually, options could appear anywhere in command line, they should not be treated as positional parameters in a script. The following command will fail even if there are all needed data in getUpdates response (because name variable in get_uid function will contain '--group'):

./zbxtg.py --group "$chatid" "Test message" "Hello" --debug

but this will work:

./zbxtg.py "$chatid" "Test message" "Hello" --group --debug

There are some handy libraries to do this dirty work ;) https://docs.python.org/3.3/library/argparse.html

Perlovka avatar Sep 04 '17 12:09 Perlovka

  1. I will test it from the beginning and will fix documentation if it is true. Thanks.
  2. I repeat: zabbix doesn't care. I know about argparse lib.

ableev avatar Sep 04 '17 12:09 ableev

it works on this command ./zbxtg.py GroupName “@BotName” “Test Message Here” --group

BenePhetes avatar Oct 09 '17 08:10 BenePhetes

I had the same issue in a group. I created group, added bot there, setup action in Zabbix and all worked for a month.

Then suddenly messages were gone.

After i removed bot from a group and add it again, the problem was fixed. @ableev how i can avoid these problem in the future?

DeV1L avatar Jan 19 '18 13:01 DeV1L

Changing zbx_tg_tmp_dir to "/var/tmp/" + zbx_tg_prefix and updating zbxtg.py helped.

DeV1L avatar Jan 19 '18 15:01 DeV1L

Using Zabbix 4.0 is failing (using private cahannel).

The thing is, that Zabbix 4.0 is using "PrivateTmp", so the file gets mapped to /var/tmp/systemd-private-<some_random>-zabbix-server.service-<another random?>

Private channels needs manually hacked uid list. I would pass it as an argument, but the if zbx_to.isdigit() fails, because the id starts with an -.

MasterMind2k avatar Apr 27 '19 19:04 MasterMind2k

Following the https://github.com/ableev/Zabbix-in-Telegram/wiki/Change-zbx_tg_tmp_dir-in-settings helped :).

I would recommend to split persistant and non-persistant data. uid mapping should (I guess) be in /var/lib/zabbix, while everything else could be in /tmp.

Justmy 5 cents :) (its quite late right now :D )

MasterMind2k avatar Apr 27 '19 19:04 MasterMind2k

When using Channel ID its mention

You need start a conversation with your bot first in '[CHANNEL ID]' group chat, type '/start@abcbot'.

How to mention start conversation to bot in channel. (Public Channel)

azriomar avatar May 29 '19 02:05 azriomar

When using Channel ID its mention

You need start a conversation with your bot first in '[CHANNEL ID]' group chat, type '/start@abcbot'.

How to mention start conversation to bot in channel. (Public Channel)

I have the same problem...

execcr avatar Jul 01 '19 12:07 execcr

@azriomar @execcr , the sending is the same as for regular username.

ableev avatar Jul 01 '19 12:07 ableev

I do encounter the same issue as well. Either zbxtg.py: User 'admin' needs to send some text bot in private or zbxtg.py: You need start a conversation with your bot first in '' group chat, type '/start@zabbix2231Bot'

No idea on how to resolve it I do check on Youtube which they are using Ubuntu to setup Telegram Notification but I am using CentOS, suppose no issue on that. Just curious the issue is persist on my side

ongsunglau avatar Sep 24 '19 06:09 ongsunglau

Work perfectly when use @username or groupname in media\action\send to:

madmorf avatar Oct 26 '19 22:10 madmorf

First of all, great work on these scripts. Love using them, but i'm having the same issue or simular.

At first, all works fine. We receive alerts and graphs in telegram (group where bot is member of), but after some period of not sending alerts (we don't send many), we have to re-initiate the bot for some reason. This message appears in Zabbix:

You need start a conversation with your bot first in '[CHANNEL ID]' group chat, type '/start@abcbot'.

Any idea how we can permanently activate the bot?

Fabian1976 avatar Mar 10 '20 09:03 Fabian1976

First of all, great work on these scripts. Love using them, but i'm having the same issue or simular.

At first, all works fine. We receive alerts and graphs in telegram (group where bot is member of), but after some period of not sending alerts (we don't send many), we have to re-initiate the bot for some reason. This message appears in Zabbix:

You need start a conversation with your bot first in '[CHANNEL ID]' group chat, type '/start@abcbot'.

Any idea how we can permanently activate the bot?

I have the same error. I have been strugling with the problem for one week. I couldn't solve it also. I use Zabbix 5.2.2 version. Could it be regarding to the zabbix version?

th3n3xtg3n3ration avatar Dec 17 '20 22:12 th3n3xtg3n3ration

I found how to fix this!

Is has to do with this parameter: zbx_tg_tmp_dir. It has to be a directory where Zabbix has write access. The script tries to write the ID of the telegram-group to a tmp file. If it can't do that, it relies on the cache on the telegram server side which runs out after X couple of days. I changed the zbx_tg_tmp_dir to zabbix home folder /var/lib/zabbix and now it is able to write it's local cache file and it keeps on working (for several months allready).

Fabian1976 avatar Dec 18 '20 07:12 Fabian1976

I had the same problem, resolve this with replace 'channel' to 'group' in line https://github.com/ableev/Zabbix-in-Telegram/blob/master/zbxtg.py#L797

Not sure about the fix, but it worked for me right away.

Dzirrot avatar Feb 28 '21 19:02 Dzirrot

I had the same problem, resolve this with replace 'channel' to 'group' in line https://github.com/ableev/Zabbix-in-Telegram/blob/master/zbxtg.py#L797

Not sure about the fix, but it worked for me right away.

It`s work for me

partizanes avatar Mar 21 '21 15:03 partizanes

I had the same problem, resolve this with replace 'channel' to 'group' in line https://github.com/ableev/Zabbix-in-Telegram/blob/master/zbxtg.py#L797 Not sure about the fix, but it worked for me right away.

It`s work for me

It works for me too. I can recommend it as fix. Thank you partizanes

adamzolo avatar Jun 15 '22 21:06 adamzolo

Hi everyone! I had some problem: "You need start a conversation with your bot first in 'name group chat' group chat, type '/start@company_bot

I fix this problem to add uids telegram groups or peaple into the file /var/tmp/zbxtg/uids.txt on zabbix server: example: cat /var/tmp/zbxtg/uids.txt GroupName;group;-387654322 UserName;private;823456781

Cho3DevOps avatar Apr 07 '23 03:04 Cho3DevOps