Skip to content

Commit

Permalink
Added posting to channel functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
nsniteshsahni committed Mar 21, 2021
1 parent 8af8eeb commit b1b8140
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
telegram-bot-amazon
Author: Luca Zorzi (@LucaTNT)
Author: Luca Zorzi (@LucaTNT) | Nitesh Sahni(@nsniteshsahni)
License: MIT
*/

Expand All @@ -11,6 +11,8 @@ const fetch = require("node-fetch");
const fullURLRegex = /https?:\/\/(([^\s]*)\.)?amazon\.([a-z.]{2,5})(\/d\/([^\s]*)|\/([^\s]*)\/?(?:dp|o|gp|-)\/)(aw\/d\/|product\/)?(B[0-9]{2}[0-9A-Z]{7}|[0-9]{9}(?:X|[0-9]))([^\s]*)/gi;
const shortURLRegex = /https?:\/\/(([^\s]*)\.)?amzn\.to\/([0-9A-Za-z]+)/gi;

const channelName = process.env.CHANNEL_NAME;

if (!process.env.TELEGRAM_BOT_TOKEN) {
console.log("Missing TELEGRAM_BOT_TOKEN env variable");
process.exit(1);
Expand Down Expand Up @@ -188,10 +190,19 @@ function deleteAndSend(msg, text) {
: {};

bot.sendMessage(chatId, text, options);

sendMessageToChannel(text,options);
return deleted;
}

function sendMessageToChannel(text, options){
if(!channelName){
console.log("Missing CHANNEL_NAME env variable");
process.exit(1);
}else{
bot.sendMessage("@"+channelName, text, options )
}
}

function getASINFromFullUrl(url) {
const match = fullURLRegex.exec(url);

Expand Down

1 comment on commit b1b8140

@brij0707
Copy link

Choose a reason for hiding this comment

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

Hi Nishant I need some help can we connect on telegram @ALEYFROST

Please sign in to comment.