studentofcs
studentofcs

Reputation: 65

How to avoid GroupMe bot from reading the same message twice when restarted on Heroku?

So essentially, my GroupMe bot will read in messages and look for specific commands.

Heroku automatically restarts my Dyno worker at least once every day.

However, when it does restart, my bot will scan over the last twenty messages and it will eventually find a command that it has already done, and then do the same thing again. Is there a way to fix this?

Code:

def main():

while True:
    response = requests.get(groupchat_url, params = request_params)
    if response.status_code == 200:
        response_messages = response.json()['response']['messages']
        for message in response_messages:
            if message['text'].startswith("/command"):
                <do something>

So, response_messages will have the past 20 messages and for each message, if it starts with "/command" then it will do something. When the bot restarts, it will do something again for the same command. I'm not sure if it's possible, but if someone knows something cool that could help solve this problem, I'd love to hear it.

Upvotes: 0

Views: 44

Answers (0)

Related Questions