How to get messages from a private channel using Telethon - telegram-bot

I used to get the posts from a public telegram channel using telethon and everything works fine until today that the channel became private and although I am a subscriber to the channel I can not retrieve the channel messages with the message-id like before and I get an error that the channel is private and you can not access the messages. I should mention that I am a subscriber to the channel.
I try different things and find out that telethon sign in as a bot and for that reason, the channel does not give it permission to read the channel messages. one other thing that I find out is that to make this work like before any bot should be added to the channel as an administrator to let telethon read messages like before.
does anyone know any way to retrieve messages from a private channel that we are subscribed to without adding bot as an administrator to the channel?
client = TelegramClient('session', api_id, api_hash, proxy=("socks5", 'server', port))
# connecting and building the session
client.connect()
# in case of script ran first time it will
# ask either to input token or otp sent to
# number or sent or your telegram id
if not client.is_user_authorized():
client.send_code_request(phone)
# signing in the client
client.sign_in(phone, input('Enter the code: '))
this is the way I use to sign in to my account but it signs in as a bot this way, is there any workaround not to sign in as a bot?

Related

Can you add a Nagios Acknowledgment URL to Slack messages

I'm new to nagios and my first task has been slack integration. I am using the Nagios created plugin for Slack and everything is working correctly as far as posting the message in the channels for both hosts and services. I want to add an acknowledgment URL to the message that gets sent to slack, so our team can just acknowledge through the slack message. I have tried adding the URL in various places, like the host/service definitions so I could then call it in the command Slack_notification_handlers. Is it possible to add said acknowledgement urls with the current methods I'm using? or is this something I'm going to have to make myself?

Create a channel on a discord server with webhook

I am using the discord webhook api to send messages to my discord servers channels. In a new use case I want to create a new channel with a webhook. Unfortunately I could not find any API to do so. I read through the whole documentation here: https://discordapp.com/developers/docs/resources/webhook#create-webhook
Is this even possible to do? I saw methods for a discord bot that allowed it - therefore I kinda think it should be possible with a webhook, too.
I think the Discord webhooks are only for sending messages and nothing more and you'll probably have to use a bot to create the channel if you don't want to do it manually.
Creating a webhook via discord.py API is only supported on the rewrite branch I think
Installing discord.py-rewrite
pip install git+https://github.com/Rapptz/discord.py#rewrite
import discord
from discord.ext.commands import Bot
bot=Bot(command_prefix='.')
#bot.event
async def on_ready():
print(bot.user.name)
#bot.command()
async def chan(msg):
chan=await msg.guild.create_text_channel(name='New text')
web=await chan.create_webhook(name='New web')
print(web.url)
bot.run("YOUr bot token here")
you can find the documentation here and you can create your bot here

stop gcm to send notification on old registration id

Suppose that case when the client app has re-registered with the gcm itself but the server is unaware of this and now the server is sending notification to that particular client what I want is the notification should not be sent with the old registration id. How can this be done?
If your server sends a message to an invalid Registration token, it will probably receive a NotRegistered error response. You should handle this error accordingly by removing the corresponding token. As per the documentaion I linked above:
For all these cases, remove this registration token from the app server and stop using it to send messages.

Any way to get more details on GCM failure?

I'm currently working on a push notification API that will work with several apps at once, handling notifications and reducing programming time for future apps. It's already partially working, as I'm able to register and receive notifications on Android devices.
Eventually, one of our apps is gonna send broadcast notifications to registered users. But some tokens might be expired, which will lead to a GCM failure. I already tested, and it seems that sending an array of tokens to GCM with a single http call is working really well, as devices with valid tokens got their notifications.
What I wasn't able to find searching GCM documentation was a way to get more details in case of failure. For example, when I send a notification to two users, one with a valid token and the other with an invalid one, I got this result :
{
"multicast_id":7625209716676388798,
"success":1,
"failure":1,
"canonical_ids":0,
"results":[
{"error":"InvalidRegistration"},
{"message_id":"0:1466511379030431%c4718df8f9fd7ecd"}
]
}
We can see that one of the messages failed to send, but what I'm looking for is a way to get more details, ideally the token that leads to a failure, so I can remove it from my database.
Any way to achieve that ? Using the message_id maybe ? Or is there any solution for me to find invalid tokens stored in my database so I can clear them ? I might have missed something in the documentation, even a link to it would be useful.
Based from this documentation, the GCM server will respond to your server with some information about the token you used to try to send the push notification.
According also to this link, if the app server fails to complete its part of the registration handshake, the client app should retry sending registration token to the server or delete the registration token. Wiping old tokens from the GCM servers can be done with ÌnstanceID.deleteToken().
Check these links:
How to remove gcm id from server which is not used
GCM get invalid tokens when sending to multiple devices at once

Receive offline message with XMPP

I am working on a chat app using XMPP Protocol.
I tried following
this tutorial from github . Everything is working fine using
XMPP.
But I'm unable to receive offline messages when user comes
online.
As user A is logged out and user B sends messages to user A, and when user A logs into app, it must receive all the messages that
were sent by user B during offline session.
How can I receive these offline messages?
My app is totally stuck on this issue. Please help if anyone
knows the solution. Any help will be appreciated. Thanks
You need to enable mod_offline on server, if you are using ejabberd XMPP Server.
Here is the code needs to enable module:
ignore_pep_from_offline: true
max_user_offline_messages:
admin: 5000
all: 100
mod_offline:
access_max_user_messages: max_user_offline_messages
Write this code in ejabberd.yml config file.
It will store unto 100 messages per user received when client was offline.
At client side, you may have to register for service:
'http://jabber.org/protocol/disco#info'
If you done this, whenever offline client gets online, server will send those stored messages to respective client.
You've to send Request for offline message if server supports. XMPP works on TCP protocol so as soon as client is up, it should send request to server.
<iq type='get'>
<query xmlns='http://jabber.org/protocol/disco#info'
node='http://jabber.org/protocol/offline'/>
</iq>