Hi everyone! Is there anyone aware java library called telegrambots? I have

a small problem here.

My bot turned 100k users and I explored from the logs a lot of errors like that:

Nov 30 01:42:09 erdees java: org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException: Error sending message: [400] Bad Request: have no rights to send a message

My bot uses addon "telegrambotsextensions" which allows to send timed messages and not get banned because of lots of requests.

but this 400 "have no rights to send a message" really bothering me. So I explored that some chats could actually add restrictions to my bot (not delete it, but disallow sending messages for example) so I tryed to check it. And here are the problem:

To get information about restrictions in my bot, I use:

GetChatMember getchatMember = new GetChatMember();
getchatMember.setChatId(String.valueOf(update.getMessage().getChatId()));
try {
getchatMember.setUserId(getMe().getId());
} catch (TelegramApiException e) {
e.printStackTrace();
}
ChatMember member;
try {
member = BotInitializer.getInstance().execute(getchatMember);

out.println( member);

result is a member object containing the followiing:

ChatMemberRestricted(status=restricted, user=User(id=111111111, firstName=mybotbotbot, isBot=true, lastName=null, userName=usercabronbot, languageCode=null, canJoinGroups=null, canReadAllGroupMessages=null, supportInlineQueries=null), isMember=true, canChangeInfo=true, canInviteUsers=true, canPinMessages=true, canSendMessages=false, canSendMediaMessages=false, canSendPolls=false, canSendOtherMessages=false, canAddWebpagePreviews=false, untilDate=0)

so as you may see there is a limitation, for sure.

Now finally the question:

In telegrambots java library you actually can't use method boolean member.canSendMessages() because it has no implementation in the library. Object content is just a test, and even not a json so I can't parse it using gson or something.
Of cource, I can parse it as is, but it is ugly solution.

There is some deserializer for the ChatMember object, but I don't know how to use it.
Maybe someone knows how to use it? Or someone knows how can I get source json responce to further parsing? thnx in advance.

7 ответов

18 просмотров

Aren't you trying to send PMs?

Sergejus- Автор вопроса
Encrypted
Aren't you trying to send PMs?

No, why? My bot primary uses in chats. But they can do it is a PM as well (PM is a private message, right?) As I understand from the logs, the problem is relevant for group chats only. In PM you can't make restrictions partly as in group.

There even is a group for that library. https://t.me/JavaBotsApi

Sergejus- Автор вопроса
Sergejus- Автор вопроса
Encrypted
Maybe bot got muted in some of chats?

exactly. I almost sure, this is not a problem. the problem is in using canSendMessages() method in the library

Похожие вопросы

Карта сайта