Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added quick reply feature #3

Merged
merged 3 commits into from
Jul 9, 2018
Merged

Conversation

abhishekchotaliya
Copy link

No description provided.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 4.667% when pulling 964a69c on abhishekchotaliya:master into a216e97 on botmasterai:master.

@coveralls
Copy link

coveralls commented Jul 5, 2018

Coverage Status

Coverage decreased (-0.3%) to 4.965% when pulling 5f8738a on abhishekchotaliya:master into a216e97 on botmasterai:master.

@abhishekchotaliya
Copy link
Author

Please note that some changes are required in the botmaster repository to implement quick reply feature in botmaster-twitter-dm.

@jdwuarin
Copy link
Member

jdwuarin commented Jul 5, 2018

Thanks for this request. I've added a few comments above so that I can merge the code in. Should be like 5 minutes to do so.

Cheers

This code is sufficient to enable quick reply feature for botmaster-twitter-dm module.
__sendMessage(rawMessage, send_options, quick_reply = false) {
console.log("rM");
console.log(util.inspect(rawMessage, false, null))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These console.logs should be removed

if (message.quick_replies) {
// construct the quick replies for twitter platform

let newObj = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename newObj to quickReplyFormattedMessage and should be const

resolve(data);
});
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code should look like this:

return new Promise((resolve, reject) => {
  // if sending events like quick replies, add /events to url
  this.twit.post(`direct_messages${rawMessage.event ? '/events/' : '/'}new`, rawMessage, (err, data) => {
    if (err) {
      reject(err);
    }
    resolve(data);
  });
});

or if wanting to be more explicit:

// if sending events like quick replies, add /events to url
const sendMessageUrl = rawMessage.event ? 'direct_messages/events/new' : 'direct_messages/new'
return new Promise((resolve, reject) => {
  this.twit.post(sendMessageUrl, rawMessage, (err, data) => {
    if (err) {
      reject(err);
    }
    resolve(data);
  });
});


// convert default quick reply structure to twitter supported structure

let data = message.message.quick_replies;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data should be renamed to quickReplies. It should be a const as the object is never overwritten. You should be using the eslint config from the project here (found in the lib directory)

metadata: data[d]["title"]
}
quick_replies.push(temp)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole code should be changed to:

const quickReplies = message.message.quick_replies.map(quickReply => ({
  label: quickReply['title'],
  metadata: quickReply['title']
}))

If you would rather use a loop, it should look like this:

const quickReplies = []
for (const quickReply of message.message.quick_replies) {
  quickReplies.push({
    label: quickReply['title'],
    metadata: quickReply['title']
  })
}

text: message.message.text,
quick_reply: {
type: "options",
options: quick_replies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should then use the quickReplies object

}
quick_replies.push(temp)
}
let quickReplyObject = {
Copy link
Member

@jdwuarin jdwuarin Jul 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a const as it is not reassigned

@abhishekchotaliya
Copy link
Author

Hi @jdwuarin,
I've made all the suggested changes. Hopefully, this time you can merge the branch!

@jdwuarin
Copy link
Member

jdwuarin commented Jul 9, 2018

@abhishekchotaliya - looking good to me. If you can confirm that this all works for you with both quick replies and normal messages, I'll go ahead and merge it.

@abhishekchotaliya
Copy link
Author

Yeah, it is working with both normal messages and quick replies.
Quick reply implementation is not breaking any existing functionalities.

@jdwuarin jdwuarin merged commit 02f2cb3 into botmasterai:master Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants