Giter Club home page Giter Club logo

telegram-bot-amazon's Introduction

This is a Telegram bot that, if made admin of a group, will delete any message containing an Amazon link and re-post it tagged with the specified affiliate tag.

It can be either messaged directly, or added as an administrator to a group or supergroup.

If messaged directly, it replies with the affiliate link, while in a group it will delete any message containing an Amazon link and replace it with a new message, with a format that is customizable through the GROUP_REPLACEMENT_MESSAGE environment variables.

Configuration

It requires two parameters through environment variables:

  • TELEGRAM_BOT_TOKEN (required) is the token obtained from @Botfather.
  • AMAZON_TAG (required) is the Amazon affiliate tag to be used when rewriting URLs.

You can set two optional parameters through environment variables:

  • SHORTEN_LINKS: if set to "true", all the sponsored links generated by the bot will be passed through the bitly shortener, which generates amzn.to links.
  • BITLY_TOKEN (required if SHORTEN_LINKS is "true") is the Generic Access Token you can get from bitly.
  • AMAZON_TLD is the Amazon TLD for affiliate links (it defaults to "com", but you can set it to "it", "de", "fr" or whatever).
  • GROUP_REPLACEMENT_MESSAGE specifies the format for the message that gets posted to groups after deleting the original one. If not set, it will default to Message by {USER} with Amazon affiliate link:\n\n{MESSAGE}. In the following table you'll find variables you can use.
  • RAW_LINKS: if set to "true" disables this bot's "URL beautifier" (which removes all the URL parameters aside from the ASIN and the affiliate tag) and just adds/replaces the tag to the URL. This allows to link to arbitrary pages on Amazon, even non-product ones (e.g. search pages, category pages, etc.)
  • CHECK_FOR_REDIRECTS: if set to "true" the bot will look for redirects in the provided links. This allows it to find links to Amazon even if they are hidden behind URL shorteners. Please note that this check requires a bit more time than looking for "regular" Amazon URLs, since the bot needs to connect to each URL.
  • CHECK_FOR_REDIRECT_CHAINS: if set to "true" the bot will perform a recursive search for redirects. This allows it to catch Amazon URLs even if they are hidden behind a chain of redirects. This will slow down the processing of redirects.
  • MAX_REDIRECT_CHAIN_DEPTH: if CHECK_FOR_REDIRECT_CHAINS is enabled, it will limit the number of redirect levels the bot will try to go through. It default to 2, and it should be kept at a low number to avoid wasting time going through endless redirect chains a user might provide.
  • IGNORE_USERS: a comma-separated list of usernames (starting with the "@" character) and numeric user IDs whose messages won't be acted upon by the bot, even if they contain matching Amazon links. A valid list would be "@Yourusername,12345678,@IgnoreMeAsWell123". Numeric user IDs are useful for users who do not have Telegram user names defined. You can get yours by contacting userinfobot.
  • CHANNEL_NAME: the name of a channel to relay affiliated links to. You must first add your bot as an admin for that channel. Feature added by adapting @nsniteshsahni's commit
String Replacement
{USER} The user that posted the message, as @username if they created a Telegram username, as first_name last_name otherwise.
{ORIGINAL_MESSAGE} The user's original message, with no replacements (so it will contain the non-affiliated Amazon link).
{MESSAGE} The user's message, with the affiliated Amazon link the bot created.

Running the app

You can either run the app directly through NodeJS

TELEGRAM_BOT_TOKEN=your-token AMAZON_TAG=your-tag node index.js

Or you can run it in Docker

docker run -e TELEGRAM_BOT_TOKEN=your-token -e AMAZON_TAG=your-tag --init lucatnt/telegram-bot-amazon

Note that the --init option is highly recommended because it allows you to stop the container through a simple Ctrl+C when running in the foreground. Without it you need to use docker stop.

telegram-bot-amazon's People

Contributors

dependabot[bot] avatar lucatnt avatar nsniteshsahni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

telegram-bot-amazon's Issues

Error

Can you please guide to overcome this error

2023-05-04T10:04:48.258472+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2023-05-04T10:04:48.297510+00:00 heroku[web.1]: Stopping process with SIGKILL
2023-05-04T10:04:48.319621+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2023-05-04T10:04:48.464919+00:00 heroku[web.1]: Process exited with status 22
2023-05-04T10:04:48.514661+00:00 heroku[web.1]: State changed from starting to crashed

Automatically get AMAZON_TLD

Actually you must set AMAZON_TLD otherwise all links will be putted as amazon.com, to have the bot automatically working on all TLDs can we just read the TLD from the link we are sending instead of forcely put a custom one?

is this outdated ???

everything done in 2 different scenario in local machine and also online getting same error

as this Missing TELEGRAM_BOT_TOKEN env variable

i know i have created env file also properly no name for that file same error

am i mission or is it really outdated

Need an option to sponsor every amazon link

As of today, the bot only affiliates Amazon product page link: this is done in order to have clean links, with just the ASIN and the affiliate tag.

There should be an option to enable the affiliation of any Amazon page, without bothering to clean the URL (which will likely be hidden in a short link anyway, by enabling SHORTEN_LINKS, implemented after #2).

From where does it forward?

From where does it forward the links? Also will it forward the photo or take it from amazon?
BTW do u have a telegram i can contact you?

Ignored users are ignored even in one-to-one chats

With #7 I added the option to have some users ignored by the bot.
This should only apply to group chats, but at the moment it also applies to one-to-one chats, so these users cannot chat with the bot to have links sponsored.

GROUP_REPLACEMENT_MESSAGE

Hi,

Probably a silly question, but how do I make changes to the index.js? I need to change the GROUP_REPLACEMENT_MESSAGE, however can't seem to find a way to do it.

I managed to get the bot to work by running the docker command, but it works with the default values

Thanks in advance.

Azure Conatainer Instances Deployment Errors since few weeks ago

Hi!
I had for a lot of time a Container Instance in my azure subscription working well. But... i clicked in stop by error, and it didn't start anymore with an error like "inaccessibleImage".

Well...so I decided to deploy it from zero again, so easey. Now the problems.. it's been impossible for me to deploy again the image, it only works if I run it in my docker desktop at home, why? dont know, maybe someone can help me.

Here an screenshot with the deployment failure:
image

I tried with ":latest" at the end of the url to the docker image. I tried without nothing, just with "lucatnt/telegram-bot-amazon" as the readme file says. But impossible mission.

Here another screenshot of the deployment with the parameters used:
image

Thank you in advanced and thank you @LucaTNT for this amazing job!

enhanchment merge CHECK_FOR_REDIRECTS, CHECK_FOR_REDIRECT_CHAINS, MAX_REDIRECT_CHAIN_DEPTH

As all these value basically do the same thing i suggest to merge all in a single env, probably the MAX_REDIRECT_CHAIN_DEPTH is enough:

MAX_REDIRECT_CHAIN_DEPTH=0 disabled
MAX_REDIRECT_CHAIN_DEPTH=1 similar to have CHECK_FOR_REDIRECTS to true (check just the first redirect)
MAX_REDIRECT_CHAIN_DEPTH=2 (or any >1), actual behaviour of max redirect to follow (but witouth the need to set also CHECK_FOR_REDIRECT_CHAINS)

Bot crash

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

Stopping process with SIGKILL

Process exited with status 137

State changed from starting to crashed

Add support for channels

As mentioned in #18, channels are not currently supported.

This needs to be investigated and, if possible, implemented.

Bot not workink if pc shut down

Hi, If i shut down pc, the bot not working, if i open the docker app then it starts working. Is there a method to make this bot working forever?

Idea: Shortlink support

I think there should be an option to have all links the bot generates be shortened through bitly, in order to get nice and short amzn.to links.

I'm trying the bot on docker but I'm having problems

Hello Luca, thank you for this bot!

I tried to use the docker image, I've changed the bot taken from botfather, the amazon code and the amazon nationality.

docker run -e TELEGRAM_BOT_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -e AMAZON_TAG=Codice00-21 -e AMAZON_TLD=it --init lucatnt/telegram-bot-amazon
I can see this log for the container created.

`Mon, 08 Mar 2021 18:25:59 GMT node-telegram-bot-api deprecated Automatic enabling of cancellation of promises is deprecated.

In the future, you will have to enable it yourself.

See yagop/node-telegram-bot-api#319. at node:internal/modules/cjs/loader:1108:14

Missing GROUP_REPLACEMENT_MESSAGE env variable, using the default one`

If I write privately to the bot he doesn't reply.

Do I have to do anything after running the container?

ps. Does the bot work in channels? Does it work with a previous affiliated link?

Thank you!
Alessandro

amzn.eu non viene intercettato

Ciao Luca, il bot non è in grado attualmente di intercettare gli shortlink con dominio eu.
Ho visto che c'è già una segnalazione nel 2023 ma dubito sia mai stata gestita: #85
Grazie per il tuo lavoro 😄

Bot freezed / error logs with no time

Still haven't understant exactly what causes the issue, but on long running my bot seems freezed and the last container logs are

error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: getaddrinfo EAI_AGAIN api.telegram.org"}
error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: getaddrinfo EAI_AGAIN api.telegram.org"}
error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: getaddrinfo EAI_AGAIN api.telegram.org"}
error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: getaddrinfo EAI_AGAIN api.telegram.org"}
error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: getaddrinfo EAI_AGAIN api.telegram.org"}
error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: getaddrinfo EAI_AGAIN api.telegram.org"}

the only way to get it back to work is to restart the container (is still running but just does not reply to messages)... do you know what can be the culprit? can we add the date and time also on these exception?

Da dove cominciare

Ciao a tutti ho scaricato il file zip ma non so proprio da dove iniziare

Schermata 2022-12-22 alle 11 57 46

help, please!

hi, i can't get it to work in any way it says to me: Missing TELEGRAM_BOT_TOKEN env variable can you help me?

Support for amazon.it

Hello, i did all the things you write and my bot workink! But the bot gave to people links of amazon.COM, i'm in italy and the link is invalid but if i change manually the website url in amazon.IT, it works without problems. I used the docker method

GROUP_REPLACEMENT_MESSAGE variable not working in answers

Hi Luca! first of all congrats for this amazing work, too many time looking for something like this.

But since a week ago using it, I don´t know why, the bot stops answering with the automated response, or with a customized one.

Tried to not passing the variable "GROUP_REPLACEMENT_MESSAGE", to use your predefined one, but is not working. I saw that you didn't change anything in the main code, but dont know why the bot only answers with the modified amazon link, without deleting the original message, and without maintaining the original text message.

Hope you can fix it, and pass paypal to make you a donation ;)

Thanks a lot in advanced!

Messed up final URL when given a link to a promotion page

I noticed that when the bot is given a link to a promotion page it results in a link that is not usable.

Is there a way that when give a link like this, the bot can avoid or correct the final resulting link?

I'm assuming that the bot is not able to find a proper ASIN because it is not a product page.

Example:
Bot is given a short link -> Expands URL -> If the result is "https://www.amazon.com/promotion/*" -> Return original link (even if it can't find the ASIN or switch the tag)

Example from bot:
Long URL https://amzn.to/3FghFhW -> ASIN https://www.amazon.com/promotion/psp/A3NGTCD7IZOQ2C?&linkCode=sl2&tag={TAG REMOVED}&linkId=39f0e7ec60dd32e40e61547061091777&language=en_US&ref_=as_li_ss_tl

It's Getting Crash After Few Minutes

2021-09-16T15:24:39.241336+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2021-09-16T15:24:39.355310+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-09-16T15:24:39.551677+00:00 heroku[web.1]: Process exited with status 137
2021-09-16T15:24:39.617010+00:00 heroku[web.1]: State changed from starting to crashed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.