feat(notification): twitter integration (#224)

This commit is contained in:
Bryan Berger
2020-09-22 21:49:40 -04:00
committed by GitHub
parent 9d5f430119
commit 908ed35882
7 changed files with 361 additions and 23 deletions
+10
View File
@@ -8,6 +8,7 @@ import {sendPushoverNotification} from './pushover';
import {sendSMS} from './sms';
import {sendSlackMessage} from './slack';
import {sendTelegramMessage} from './telegram';
import {sendTweet} from './twitter';
const notifications = Config.notifications;
@@ -46,4 +47,13 @@ export function sendNotification(cartUrl: string, link: Link) {
if (notifications.desktop) {
sendDesktopNotification(cartUrl, link);
}
if (
notifications.twitter.accessTokenKey &&
notifications.twitter.accessTokenSecret &&
notifications.twitter.consumerKey &&
notifications.twitter.consumerSecret
) {
sendTweet(cartUrl, link);
}
}
+29
View File
@@ -0,0 +1,29 @@
import {Config} from '../config';
import {Link} from '../store/model';
import {Logger} from '../logger';
import Twitter from 'twitter';
const twitter = Config.notifications.twitter;
const client = new Twitter({
access_token_key: twitter.accessTokenKey,
access_token_secret: twitter.accessTokenSecret,
consumer_key: twitter.consumerKey,
consumer_secret: twitter.consumerSecret
});
export function sendTweet(cartUrl: string, link: Link) {
let status = `🛎️ Stock Notification: ${link.brand} ${link.model}\n${cartUrl}`;
if (twitter.tweetTags) {
status += `\n\n${twitter.tweetTags}`;
}
client.post('statuses/update', {status}, err => {
if (err) {
Logger.error(err);
} else {
Logger.info(`↗ twitter notification sent: ${cartUrl}`);
}
});
}