I have an virtual private assistant (VPA) web application. This app has few agents available. Each agent has a set of conversations and FAQs configured inside it.
Now I am planning to integrate one of the agents from VPA app with Twitter Direct Messaging (DM). So when a user sends a DM to my twitter handle (or app handle), the message (or query) should be redirected to my application at backend.
In short, my application should act as backend service (webhook) for all queries posted onto my twitetr handle and respond automatically based on the conversations/ FAQs built inside my app.
Could you please guide me on the steps I need to follow to achieve this? I have crated a bot app using my twitter app as a first step.
I’m not currently aware of an example in Java, but I believe that several Twitter partners use these APIs from Java environments. We’d love to hear about developers interacting with the API in different languages, so please share if you hear of any.
You need to have access to the Account Activity API. You can apply via the form on this page (Apply for access to the Account Activity API - Direct Messages). Make sure you include your app ID and to explain what you are building.
A GET request with a parameter named crc_token will be sent to your webhook URL. Your endpoint must return a JSON response with a response_token that is a base64 encoded HMAC SHA-256 hash created from the crc_token and your app Consumer Secret.
This means that your application will need to respond with an encoded hash of the incoming crc_token + your consumer secret when called with the crc_token parameter. If that parameter is not present, you can assume you’re receiving a standard Direct Message event.
Thanks Andy! I have applied for access to the Account Activity API - Direct Messages and All Activities both(on 10th and 9th Jan 2018 respectively)!
Please help me with below queries -
Can you please let me know how much time will it take to get this access?
Considering my DM chatbot described above, only Account Activity API - Direct Messages is sufficient?
Is the CRC token and response_token generation mandatory step for this integration?
What is app ID ? I have applied for access usign my consumer key. Is that fine?
You mentioned - “If that parameter is not present, you can assume you’re receiving a standard Direct Message event” - Can you please elaborate ?
Last - important question -
6. Can we achieve this integration by subscribing to event (something like onDirectMessage) without having the need for webhook? So when a DM is received by my twitter handle, it will automatically trigger some function with the subscribed event ?
The team is reviewing requests for access and we’re not able to provide estimates at this time.
Yes, this should be fine since you’re just looking for Direct Message events, not others.
Yes, the webhook security is based on the receiving app correctly responding to CRC token exchanges.
It may be possible to find your app ID based on consumer key, the team will have to let you know when they get to your application. The app ID is the numerical string in the URL when you’re looking at your app on apps.twitter.com
If your app receives a call on its regular callback URL without a crc_token parameter, it will be a Direct Message JSON object. If the call has a crc_token request parameter, your app is expected to reply with a valid CRC response.
That is exactly what webhooks are - effectively, an “onDirectMessage” callback event that your app needs to respond to.
The alternative to this integration would be a non-realtime polling application that periodically calls direct_messages/events/list to check for new messages, and then responding.
I’m unable to look up the status of an application unfortunately, we appreciate your patience while we work through the applications. You should receive an email when we have approved or rejected the use case.