Is there, at the moment, any way to download messages from a public group without phone authentication? While using a bot, I get an error:
Exception has occurred: BotMethodInvalidError
The API access for bot users is restricted. The method you tried to invoke cannot be executed as a bot (caused by GetHistoryRequest)
I'd like to automate the process of getting new messages so I'm not able to authenticate every time the session starts.
Is there any workaround?
The bot can't get the message history. Bots work with updates. You can receive new messages while your bot is connected
#bot.on(events.NewMessage)
async def echo_all(event):
print(event.message)
Related
so im playing a little bit around with my telegram bot, now im already able to send normal messages and pictures. But now i want to be able to send pre recorded voice messages as an answer. In the documentation it says to use send_voice for this matter and it recommends using the file_id of a file thats already on the telegram servers. So thats what i did i send a voice message to the #RawDataBot and he returned to me the file_id of the voice message.
Problem is: When i try to trigger it i get the following error: telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: wrong file identifier/HTTP URL specified
Any ideas here on what i might be doing wrong? Here is the relevant code:
import telebot
API_KEY = <MY_API_KEY>
bot = telebot.TeleBot(API_KEY)
#start
#bot.message_handler(commands=['start'])
def start (message):
bot.send_message(message.chat.id,Textstart)
#bot.message_handler(commands=['pic'])
def start (photo):
bot.send_photo(photo.chat.id, "https://de.wikipedia.org/wiki/Zeus#/media/Datei:Zeus_Otricoli_Pio-Clementino_Inv257.jpg")
#here is the part where he is supposed to send the voice message if someone types in /audio
#bot.message_handler(commands=['audio'])
def start (voice):
bot.send_voice(voice.chat.id,"AwACAgIAAxkBAAEWjl5i5bjyudWAM9IISKWhE1Gjs5ntQgACLx8AApcNKEv97pVasPhBoCkE",)
bot.polling()
There are multiple reasons, but I think it is because of these:
file_id is unique for each individual bot and can't be transferred from one bot to another.
file_id uniquely identifies a file, but a file can have different valid file_ids even for the same bot.
See here.
I'm trying to send a Google Chat message from Python in much the same way you can send a Gmail message:
https://developers.google.com/gmail/api/quickstart/python
I see documentation on how to create a Chat Bot (https://developers.google.com/chat/how-tos/bots-develop), but these typically require that you create your own https server that google can access.
I've tried using the scope 'https://www.googleapis.com/auth/chat', and it successfully goes through the authorization flow, and in particular the 'chat' scope claims to grant permissions to send messages, etc:
(see https://vizycam.com/wp-content/uploads/2022/01/Image-634-1.jpg)
I can build a request using build() and the granted credentials:
from googleapiclient.discovery import build
...
service = build('chat', 'v1', credentials=gcloud.creds())
and I can see that it has methods dms(), rooms(), spaces(), etc. that I could use to create a message, but I'm unable to get any requests to work.
Is it possible to send a chat message from a user account programmatically, in much the same way the Gmail example above does?
I have the telegram bot written on telebot package on python.
From 03/01/2021 worked without problems. Main task of this bot parse information from documents sent by users. It also handles some commands. All other types of data forward from the user to the developer.
On January 17, 2022, 5 entries with an error appeared in the logs:
A request to the Telegram API was unsuccessful. Error code: 502 Description: Bad Gateway
After about an hour, each request from users returned with an error in the logs:
A request to the Telegram API was unsuccessful. The server returned HTTP 403 Forbidden. Response body:\n[b'<html>\\r\\n<head><title>403 Forbidden</title></head>\\r\\n<body>\\r\\n<center><h1>403 Forbidden</h1></center>\\r\\n<hr><center>nginx/1.18.0</center>\\r\\n</body>\\r\\n</html>\\r\\n']"
I find that a 403 error occurs when bot trying to download the sended document from user with the download_file() method. The part of my code where its breaks:
def handling_documents(message):
def save_file():
downloaded_file = bot.download_file(bot.get_file(message.document.file_id).file_path)
filename = message.document.file_name
The bot runs on CentOS. I tried other workplaces and problem is actual. The problem in https://api.telegram.org/file/bot_token/file_path . Any other types of messages (photos, stickers, text, etc.) the bot handling successfully, as it should.
Couldn't find a good solution on google. About 100 users use the bot daily. I can’t just wait as it is written in Telegram Bot File Download Suddenly response 403 .
I also found a solution with the revoke of the API token https://github.com/eternnoir/pyTelegramBotAPI/issues/581 But after that the problem with the 403 error remained. What could be wrong?
I use PyTelegramBotAPI 4.3.1 version, Linux Mint 20.2, PyCharm.
I didn't find help by russian community stackoverflow.
P.S. sorry for my english if it written not clear
It seems like some kind of telegram api bug. The problem resolved itself. Bot recovered after a 2-day downtime.
I am using python slack client to connect and send messages with a bot application.
slc = SlackClient("BOT_USER_TOKEN")
out = slc.api_call(method='users.profile.get', user='XXX')
I am getting not_allowed_token_type error in output json. I am able to call:
slc.api_call(method='chat.PostMessage',channel)
Is there a way to get user email, name from slack API. previously I got the username from event messages. but now I am getting only user id so I am looking for a solution to fetch user info using that id.
The reason you get this error message is that users.profile.get does not work with bot tokens.
To mitigate just use the user token that you received along with your bot token when installing your Slack app.
I'm trying to automate interaction with a website that uses websockets. In theory all I need to do is get authenticated with steam and then send 1 piece of data, but I'm having trouble getting authenticated.
I manage to get the connection set up. But after I send my steam token (replicating what I see happens in the devtools of my browser), it replies that I am not logged in.
Below is the code I currently have. Locally it doesn't work at all. But on repl.it (an online editor) it has the effect it's supposed to have but the websocket still replies that I am not logged in.
The code:
import asyncio
import websockets
import json
import time
import sys
token = "YOUR_STEAM_TOKEN_HERE"
adress = 'wss://eu.pug.champ.gg/socket.io/?EIO=3&transport=websocket'
authtemplate = '42["authenticate",{{"token":{0}}}]'
rolesupdatetemplate = '42["updateAvailability",{0}]'
async def add(roles):
async with websockets.connect(adress) as websocket:
await websocket.send(authtemplate.format(token))
roles_string = json.dumps(roles)
await websocket.send(rolesupdatetemplate.format(roles_string))
asyncio.get_event_loop().run_until_complete(add({'roles': ['roamer', 'pocket'], 'captain': False})
)
Some extra info:
When on the site normally, the websocket I'm connected to according to the developer tools has an extra argument compared to the one I use in my code. The extra argument being: sid=....
However, adding this manually gives me error code 400.
I've tried looking up how to do this but I can't find the answer anywhere. Do I need to send cookies?
Do I need to get the websocket address in another way rather than manually?
What am I missing?