How to limit replies to 1 API Call?

directmessages
streaming
javascript

#1

I’m making a Q&A twitter bot w twitter api using direct messages, my problem is each time a user ask a question, after a while, the bot start to response twice the same answers. Is there a way to limit each response to 1 API Call?

here my code:

stream.on('direct_message', function (eventMsg) {
    var msg = eventMsg.direct_message.text;
    var screenName = eventMsg.direct_message.sender.screen_name;
    var msgID = eventMsg.direct_message.id_str;

    if (screenName === ‘MyBotExample) {
        return callbackHandler(msgID);
    }

    else if (msg.search(‘Hi’) !== -1 ) {
        return T.post('direct_messages/new', { 
            screen_name: screenName,
            text: 'Hey, what can I do for you?'} , function () {
            callbackHandler(msgID);
        });
    }

    else {
        return T.post('direct_messages/new', {
            screen_name: screenName,
            text: "I don't know "
        }, function() {
            callbackHandler(msgID);
        });
    }
});

Thanks!


#2

This doesn’t seem to be an API issue.

Every DM, retweet, or status (tweet) has an ID. The only way I can see would be to store incoming IDs in a table and only respond to those that are not in the table. Otherwise, every time your bot looks for interaction it will respond again, and again etc.

Maybe someone else will have a more elegant solution.