mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 08:47:43 +00:00
feat(notification): twitter integration (#224)
This commit is contained in:
+8
-1
@@ -48,7 +48,14 @@ const notifications = {
|
||||
accessToken: process.env.TELEGRAM_ACCESS_TOKEN ?? '',
|
||||
chatId: process.env.TELEGRAM_CHAT_ID ?? ''
|
||||
},
|
||||
test: process.env.NOTIFICATION_TEST === 'true'
|
||||
test: process.env.NOTIFICATION_TEST === 'true',
|
||||
twitter: {
|
||||
accessTokenKey: process.env.TWITTER_ACCESS_TOKEN_KEY ?? '',
|
||||
accessTokenSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET ?? '',
|
||||
consumerKey: process.env.TWITTER_CONSUMER_KEY ?? '',
|
||||
consumerSecret: process.env.TWITTER_CONSUMER_SECRET ?? '',
|
||||
tweetTags: process.env.TWITTER_TWEET_TAGS ?? ''
|
||||
}
|
||||
};
|
||||
|
||||
const page = {
|
||||
|
||||
@@ -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