broidHQ / integrations

Connect your App to Multiple Messaging Channels with the W3C Open standard.
https://www.broid.ai
GNU Affero General Public License v3.0
746 stars 83 forks source link

fix(twitter): Adapter.js user not found error #177

Closed nibzo1 closed 6 years ago

nibzo1 commented 7 years ago

Issue: User not found error occurs when listening for a Tweet

Changing event.in_reply_to_user_id to use event.in_reply_to_user_id_str as described in https://dev.twitter.com/overview/api/twitter-ids-json-and-snowflake fixes user not found error.

From Twitter Documentation

When consuming the API using JSON, it is important to always use the field id_str instead of id. This is due to the way Javascript and other languages that consume JSON evaluate large integers. If you come across a scenario where it doesn’t appear that id and id_str match, it’s due to your environment having already parsed the id integer, munging the number in the process. Read below for more information on how Twitter generates its ids.

Fixing user not found in broid twitter integration.

nibzo1 commented 7 years ago

An interesting observation while fixing this issue was that when the user not found error caused the code below to stop listening correctly. We have not been able to figure out what is happening here but im assuming that this.userById(event.in_reply_to_user_id, true) this code is updating some state objects with an incorrect value, preventing the listen logic working for the correct user

Rx.Observable.merge(...R.map(client => client.listen(), R.values(clients)))
    .subscribe({
        next: message => console.log(JSON.stringify(message, null, 2)),
        error: err => console.error(`Something went wrong: ${err.message}`),
    });
dustinblackman commented 7 years ago

Thanks for this. Let me look in to that second comment of yours before we get this merged up.

nibzo1 commented 7 years ago

Great thanks for the review. It should be easy to recreate the scenario