Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facebook Messenger (Python) two different results same user #83

Open
elbination opened this issue Feb 17, 2020 · 1 comment
Open

Facebook Messenger (Python) two different results same user #83

elbination opened this issue Feb 17, 2020 · 1 comment

Comments

@elbination
Copy link

The problem is exactly the same here: https://stackoverflow.com/questions/41601267/facebook-messenger-python-two-different-results-same-user

And I can confirm this comment: "facebook's api posts back the message with the recipientID of the facebook page's ID. I know kinda weird. My guess is that you (user1) populates that list, but somewhere in between (user2 being the facebook page) also contributes to the length of the list.. idk, just a guess. what do you think? try printing out recipient IDs."

I am using Flask and Heroku for webhook server.
What should I do?

@franciswguevara
Copy link

franciswguevara commented Mar 4, 2021

Hi! Ran into the same problem. The problem lies in Heroku. The free version starts two "dynos" with two different sets of memory, that's why you get different results for the same user.

Our workaround was to add a pickle (or you can use any type of persistent memory) that tracks if a dyno messaged the user already.

if os.path.exists('df.pickle'):
            with open('df.pickle', 'rb') as x:
                df = pickle.load(x)

with open('message.pickle', 'wb') as x:
            pickle.dump(message_dict, x, protocol=pickle.HIGHEST_PROTOCOL)
 
with open('message.pickle', 'rb') as x:
            previous_message = pickle.load(x)
            check_message = previous_message

Also if I'm not mistaken we found a way to only run one dyno, I think this was the line of code that did that:

app.run(threaded=True)

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants