1

I want my bot to send a message to the telegram chat when I am active on my computer. I've wrote other functions that use this fuction to send messages.

# Function to send messages back to chat
def sendmessage(update, context, message):
    context.bot.send_message(chat_id=update.effective_chat.id, text=message)

This however uses update and context from the dispatcher and handler.

The function I want to send a message runs in a separate thread and is not using the dispatcher or handler. Thus I cannot use above function. I can't seem to figure out how to send a message without the use of update and context.

What I have now:

def user_returned():
    row_list = []
    with open('log.csv') as csv_file:
        csv_reader = csv.DictReader(csv_file, delimiter=',')
        for row in csv_reader:
            row_list.append(row)
    last_line = row_list[-1]
    second_to_last_line = row_list[-2]
    print(last_line['active'], second_to_last_line['active'])
    if last_line['active'] == 'True' and second_to_last_line['active'] == 'False':
        message = 'user is back'
        context.bot.send_message(chat_id=update.effective_chat.id, text=message)
    else:
        message = 'still gone'
        context.bot.send_message(chat_id=update.effective_chat.id, text=message)
1

1 Answer 1

1
import telegram

bot=telegram.Bot(token=bot_token)
chat=123456

bot.sendMessage(chat, msg)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.