Telethon based listener does not respond to new messages on AWS

Viewed 378

My goal is to create a Telegram listener on a specific channel that copies new messages and posts them as tweets on Twitter. So far the python I wrote works well when I run it on my computer, when I send a mock message on my Telegram channel, it detects that a message has been sent, goes down the code, and a tweet is created with the text.

However, this is not the case when I try to run in on an AWS instance (ubuntu).

when running the following code:

import tweepy
from telethon import TelegramClient, events

auth = tweepy.OAuthHandler("", "")
auth.set_access_token("", "")
api = tweepy.API(auth)

print("start")
# Listen to new messages on Telegram Channel
bot = TelegramClient("bot", api_id, api_hash).start(bot_token=bot_token)
with bot:
    print("bot-start")
 
@client.on(events.NewMessage(chats=ChannelURL))
async def newmessagelistener(event): 
    print("action detected")

client.start()
client.run_until_disconnected()

Things start out ok at the beginning, but then when I write a new test message on the telegram channel - nothing, no "action detected" is returned, only "start" and "bot-start", no tweet is posted.

Any ideas as to what's going on? Thanks in advance!

0 Answers
Related