First of all, great platform!
Next, i’m trying to cache an asyncio
function (i’m forced to use it with the library) but i’m getting this Object of type builtins.coroutine: <coroutine object get_channel_details at 0x1a9be3560>
-
Builtins
does not havecoroutine
, it’s insideasyncio
. - How can i cache it? This does not help
hash_funcs={asyncio.coroutine: lambda x: x}
(probably because it does not correspond tobuiltins.coroutine
as in the error message
Here is the function itself:
async def get_channel_details(channel):
tg_client = TelegramClient(SESSION_FILE, tg_env['TELEGRAM_APP_ID'], tg_env['TELEGRAM_APP_HASH'])
channel_details = {'title': "", 'description': "", "recent_posts": []}
async with tg_client:
ent = await tg_client.get_entity(channel)
assert isinstance(ent, tl.types.Channel)
meta = await tg_client(functions.channels.GetFullChannelRequest(channel))
posts = await tg_client.get_messages(channel, limit=10)
channel_details.update({
'title': meta.chats[0].title,
'description': meta.full_chat.about
})
if len(posts) > 0:
channel_details.update({'recent_posts': [p.message for p in posts if p.message is not None]})
return channel_details