Advanced features

In this section, we will go see some useful things that can help you enhance your Twitter Direct Messages bot.

Getting user data from Twitter

When a conversation is started on Twitter Direct Messages, with each message you will find some relevant informaiton in the user_data field object:

{
    first_name: '',
    last_name: '',
    name: 'Elon Musk',
    sender: '3302226479',
    screen_name: 'elonmusk',
    description: 'CEO of Tesla / Space X, Meme Lord',
    followers_count: 1000000,
    friends_count: 1,
    profile_picture: 'https://pbs.twimg.com/profile_images/1234/starship.jpg',
    created_timestamp: '1432851136084'
}

This allow you to have personalized greeting messages.
You can use the following code to get the name for instance.

var name = user_data.name;
output.answer = "Hello " + name + ". How are you today?"

callback(output);

This allow you, for instance to have personalized greeting messages.
You can use the following code to get the name for instance.

This will show Hello Elon Musk. How are you today?

Send multiple / dynamic / rich messages

From your Node.js code snippet, you can use some of the templates below to push dynamic messages to a Twitter direct messages conversation.

1. Simple text messages

You can use messenger_answer.push() function to send different kind of messages.
Some examples below:

var message;

//Sending the first message
message = {
    "text": "hi there"
};
messenger_answer.push(message);

//Sending the second message
message = {
    "text": "All good?"
};
messenger_answer.push(message);

callback(output);

and the result:

πŸ“˜

Delay between multiple messages

While sending multiples messages, we apply a by default delay of 2 seconds

Buttons cards
You can add buttons on your conversations see how in the Rich Messages section.

Quick Replies
You can add quick replies on your conversations see how in the Rich Messages section.

The result for the following code will be the object below:

🚧

Quick replies always at the end

If you have many messages to send at once, make sure that quick replies are set as the last one, otherwise theyw won't show properly on the Twitter client.