mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 11:07:43 +00:00
feat(notification): twitter integration (#224)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user