'Having trouble running multiple functions in Asyncio

I'm a novice programmer looking to build a script that reads a list of leads from Google Sheets and then messages them on telegram. I want to separate out the first and second message by three days thats why im separating the methods.

import asyncio
from telethon import TelegramClient
from telethon.errors.rpcerrorlist import SessionPasswordNeededError
import logging
from async_class import AsyncClass, AsyncObject, task, link
from sheetdata import *

logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s',
                    level=logging.WARNING)

api_id = id
api_hash = 'hash'

phone='phone'
username='user'
client = TelegramClient(username, api_id, api_hash)
        
#already been touched once
second_touch_array=[]

#touched twice
third_touch_array=[]

async def messageCount(userid):
    count = 0
    async for message in client.iter_messages(userid):
        count+=1
    yield count

async def firstMessage():
    #clear prospects from array and readData from google sheet
    clearProspects()
    readData(sheet)

    #loop through prospects and send first message
    for user in prospect_array:
        #check if we already messaged the prospect. If we haven't, execute function
            if(messageCount(user.id) == 0):
                await client.send_message(user.id, 'Hi')
                second_touch_array.append(prospect(user.name, user.company, user.id))
                print("First Message Sent!")
            else:
                print("Already messaged!")

async def secondMessage():
    for user in second_touch_array:
        if(messageCount(user.id) == 1):
            await client.send_message(user.id, 'Hello')
            third_touch_array.append(prospect(user.name, user.company, user.id))
            print("Second Message Sent!")
        else:
            print("Prospect has already replied!")

async def main():
    # Getting information about yourself
    me = await client.get_me()

    await firstMessage()
    await secondMessage()
    for user in second_touch_array:
        print(user.name, user.company, user.id)

with client:
    client.loop.run_until_complete(main())

Anyways, when I run my code i'm successfully getting the "Already Messaged!" print statement in my terminal from the firstMessage function.

This is good - it's detecting I've already messaged the one user on my Google Sheets list; however, my second function isn't being called at all. I'm not getting any print statement and every time I try to print the contents of the second array nothing happens.

If you have any advice it would be greatly appreciated :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source