Search code examples
twittertwitter-streaming-api

Twit Send and Receive Twitter DMs


I am trying to use Twit to send and receive Twitter DMs.

When I create a stream like this:

var stream = T.stream('user');

I get a 404 error. I believe this is because the user stream has been deprecated.

What stream can I use instead to send and receive DMs?


Solution

  • That's correct, you will need to use the Account Activity API to receive Direct Messages in realtime. This is a webhook-based API. Twitter has a migration guide.

    In summary:

    1. Create an app with a listening URL for Twitter to post events to.
    2. Register the webhook
    3. Listen for incoming Direct Messages
    4. Use the REST Direct Message API to respond.

    There's also a full tutorial on this using a JavaScript package called autohook.