node.js - If No Tweets Are Selected Don't Send Email -
been working on application www.prhunters.com scans twitter , pulls out tweets contain keywords.
the code below governs daily summary email sent out once day. however, days when there no matches email empty.
how can customise code below send when there tweets , not send when email empty?
thanks help!
export function senddailytweets({notifications}){ console.log('send daily tweets'); let promises = putvaluesinarray(mapobject(notifications, (email, matches) => { return new promise(function(resolve, reject){ //console.log(matches); let template_object = { showheader: true, date: moment().format('mmmm yyyy'), categories: [] }; mapobject(matches, (keyword, tweets) => { template_object.categories.push({ name: keyword, tweets: tweets.map( (tweet) => { return { authorimage: tweet.user.profile_image_url_https.replace('_normal','_bigger'), authorname: tweet.user.name, authorlink: 'https://twitter.com/'+tweet.user.screen_name, authorscreenname: tweet.user.screen_name, tweettext: tweet.text, tweetlink: 'https://twitter.com/'+tweet.user.screen_name+'/status/'+tweet.id_str }; }) }); }); let html = emailtemplate(template_object); mandrill.messages.send({ message: { to: [{ email: email }], from_email: 'support@prhunters.com', from_name: 'pr hunters', subject: "daily pr opportunities", html, tags: ["tweet_notification"], track_opens: true, auto_html: true, preserve_recipients: false } },function(result){ console.log('email sent!',result); if(result[0].status === "rejected" || result[0].status === "invalid"){ reject("error sending email: "+result[0].reject_reason); } resolve(result); },function(error){ console.error('error sending email',error); reject(error); }); }); })); }
the bit sends email ...
mandrill.messages.send
so need wrap code in if condition.
if (number of tweets>0) { mandrill.messages.send }
you need determine correct condition work out whether number of tweets greater 0.
look @ template_object , compare when there none versus when there matches , use determine relevant condition.
Comments
Post a Comment