Skip to content

Instantly share code, notes, and snippets.

@lubien
Last active November 21, 2023 03:06
Show Gist options
  • Star 48 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save lubien/dd31722dbb30d2ca2b7a55d21e69cfed to your computer and use it in GitHub Desktop.
Save lubien/dd31722dbb30d2ca2b7a55d21e69cfed to your computer and use it in GitHub Desktop.
Download all visible telegram stickers images
// How to download telegram sticker images
/*
1. Go to Telegram Web;
2. Open console (F12);
3. Paste the code below in the console and press Enter;
4. Open your stickers menu and make sure you see the sticker pack you want to download (so Telegram will load it).
5. At the console paste and run "downloadStickers()" any time you want to download a pack.
6. [Convert .webm to another format](http://www.freewaregenius.com/convert-webp-image-format-jpg-png-format/);
7. Happy hacking.
If you close the tab or refresh it, you should do step 3 again.
*/
// Main function
function downloadStickers() {
// Find all sticker sets
const sets = querySelectorAll('.composer_stickerset_wrap')
// We need it's title to prompt users
.map(set => {
const $title = querySelector('.composer_stickerset_title', set);
return {
key: $title.attributes['data-stickerset'].value,
title: $title.innerText,
node: set,
};
})
// Those without key aren't packs. "Frequently used" for example.
.filter(({key}) => key !== '');
// Ask which pack the user want to download
const selectedSet = prompt(
// Join them into a list of keys-titles
sets
.map(({title}, i) => `[${i}]: ${title}`)
.join('\n')
);
// Find all images
querySelectorAll('img', sets[+selectedSet].node)
// Only care about it's URL
.map(i => i.attributes.src.value)
// Filter those with `sticker` in the URL
// .filter(i => /sticker/.test(i)))
// Download all
.forEach(download);
}
// DOM query helpers
// These two do 90% of what you need JQuery for
const querySelector = (query, el = window.document) =>
el.querySelector(query);
const querySelectorAll = (query, el = window.document) =>
Array.from(el.querySelectorAll(query));
// Trigger a download
function download(image) {
// Create a dummy element
var a = document.createElement('a');
a.href = image;
// `download` attribute means that clicks trigger download
a.download = "";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
@EhsanHadid
Copy link

it doesn't work for me
i just copy whole codes
in telegram web i went to console
then send one of the sticker to my self and then click on it to open
and i paste the code and enter

but i see " undefined " down there

please help me

@broncotc
Copy link

@Ehsan123456789 you need to execute the function after define them.

@satouriko
Copy link

To friends who would like to download stickers,
https://telegram.me/stickerset2packbot
this bot can resolve high resolution images XD

@EXL
Copy link

EXL commented Feb 17, 2018

@rikakomoe, thank you!

@GertSchepens
Copy link

Great work, thanks ^^

@telegramuser
Copy link

Great bot! Thanks a lot OP! I am looking for this for a while now to download some telegram stickers packs :)

@ishanSrt
Copy link

@rikakomoe that bot works great!! is there something by which i can download entire packs? whos project is that bot?

@nguyenlehai
Copy link

very thanks 👍

@phoenixlzx
Copy link

@rikakomoe @ishanSrt It's mine and it's open source. https://github.com/phoenixlzx/telegram-stickerimage-bot
https://t.me/stickerset2packbot

I finally have some time to update the code. Now you may try with send this bot a sticker link (something like https://t.me/addstickers/Amashiro_Natsuki ) after /newpack
Or send individual sticker to get a PNG without /newpack

Both are new added features.

@Shesh93
Copy link

Shesh93 commented Nov 13, 2018

It works for me

@jarvis3439
Copy link

this bot is very good

@lubien
Copy link
Author

lubien commented Jun 4, 2019

Surprised to see there where people over here as GitHub doesn't notify at all about comments on gists.

Bot is the way to go :)

@qiyuhao7
Copy link

To friends who would like to download stickers, https://telegram.me/stickerset2packbot this bot can resolve high resolution images XD

The bot does not work, I create another instance https://t.me/AnotherStickerDownloadBot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment