Telethon get messages from private Telegram channels - telethon

I am trying to retrieve message from a private Telegram channel. I am the member of the channel and I can see the messages both on Telegram app and Telegram Web.
I tried the following code which works as expected and prints messages for non-private channels. However, when I input the name/ID of the private channel the output is an empty string.
Is this due to the issue in the code, or it is not possible to access private messages through Telethon?
Thank you.
async with client:
async for msg in client.iter_messages(client ID integer not string, 5):
print(msg.text)

It is possible to get messages from private channels with client bot (like real user) not chat bot.If you use numerical ID, add -100 prefix. Check this answer.

Related

How to send message as a channel telethon

Is this even possible using telethon?
I want to use the send message as channel in public groups option using telethon.
I couldn't find anything about it anywhere
Seems like there is this send_as attribute in send_message for the master branch of Telethon and it's not released yet.

Telegram bot doesn't recieve messages from a channel

Private settings are turned off.
the bot is added to the channel and he is an admin.
i created another channel because maybe the other one had problems but it didn't helped too.
And it still can't see the messages i send in the channel , why?
(i tested it and he gets the messages everywhere except of channels)
consider that channel_post is a different update parameter than regular message parameter which is only for private chats and groups.
check more in: https://core.telegram.org/bots/api#getting-updates

how do I retrieve the latest telegram bot messages posted in a channel through the api?

I want to see the last post a bot makes to my channel through the API/https
I tried getUpdates and it only shows messages I sent to the bot. I'd like to see messages the bot broadcasts to my channel
https://api.telegram.org/botxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/getUpdates
The getUpdates method only retrieves messages that are sent to the bot by normal users. Bots cannot see other bot messages, that means it cannot see its own messages. However you can track messages sent by the bot in your code logic. E.g. in Node.js you would do something like:
bot.sendMessage(channelId, "The message sent to the channel").then(ctx => {
// ctx contains the details of the message sent to the channel
// you can do whatever you want with it
});

Telegram Bot - Send Info message

currently I am working to creating telegram bot. Now I required to know is there is any API to send info messages (like the one we get during a user is added r deleted in a group chat)
Thanks in advance
What you want to do can be done using answerCallbackQuery method.
But first of all you have to create a CallbackQuery using InlineKeyboardMarkup to create inline keyboards you can follow the steps in this link.
After creating the callback query you have to answer it using one of the codes below:
if (update.CallbackQuery.Data == "CQ1")
{
await Bot.AnswerCallbackQueryAsync(update.CallbackQuery.Id,"Text",true,null, 0);
}
This way the message will look like a message box and will disappear after the user taps on OK. But if you use the code below, the message will show up and disappear automatically after a few seconds.
else if (update.CallbackQuery.Data == "CQ2")
{
await Bot.AnswerCallbackQueryAsync(update.CallbackQuery.Id, "Text", false,null, 30);
}
By the way, messages that are shown at times like adding a user to a
group are service messages and theses kinds of message can only be
sent by telegram server.
If my suggestion does not fix your issue you can use pinMessage method
that sticks a single message to the top of the page in groups and
channels. But note that you can only pin one message to a channel
or group and for pinning another message firstly you should unpin the
previous one.
Currently there is no way to send such info messages.
And in my opinion, this feature is unlikely to be added in future because:
info messages usually tell you information about your chat; they are managed by telegram servers
therefore they should not be sent by Users
bot is an instance of User

Android phone won't receive SNS push notifications

I have a few Android phones. I'm pushing messages to them via Amazon SNS to GCM, using boto in Python. One phone always receives the messages. The other one does not.
The first time I send a message to the problem phone, it appears to succeed but nothing goes through. When I go to the AWS console and look at the list of endpoints registered to my app, it now shows "false" under the Enabled column.
The second time I send a message, boto raises an exception with a message in it: "Endpoint is Disabled"
What are some reasons why an android phone would not receive GCM messages? Are there user settings that can disable this?
Probably you figured it out, however, I post the answer for future use. This is a good article around this topic and addresses some possibilities about the problem.
Based on your explanation I think the Token for the android phone is expired and it needs to get re-registered with the GCM, then the SNS endpoint should be updated.
Token may have expired, or it may have been cleared from the app's storage. On your Android app, create a class that extends FirebaseInstanceIdService and override this function:
#Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// If you want to send messages to this application instance or
// manage this apps subscriptions on the server side, send the
// Instance ID token to your app server.
sendRegistrationToServer(refreshedToken);
}
Also create your own sendRegistrationToServer. On your backend, implement a function that receives the token and assigns it to that endpoint's ARN. This way, your backend will always know where to send the notification.