Skip to content

Commit

Permalink
Merge branch 'SebaUbuntu:master' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
Rikj000 committed Dec 15, 2021
2 parents 60c0d32 + 744bc0d commit 663928d
Show file tree
Hide file tree
Showing 5 changed files with 1,143 additions and 577 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -121,3 +121,9 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# Ignore JetBrains IDE
/.idea/

# Ignore CKP Bridges
*ckp*
41 changes: 21 additions & 20 deletions backends/telegram.js
@@ -1,31 +1,32 @@
import TelegramApi from "natsvora-telegram-bot-api";
import TelegramBot from "node-telegram-bot-api";

const TELEGRAM_BOT_TOKEN = process.env.TELEGRAM_BOT_TOKEN;

console.log("Telegram bot token: " + TELEGRAM_BOT_TOKEN);

export var telegram = new TelegramApi({
token: TELEGRAM_BOT_TOKEN,
updates: {
enabled: true,
pooling_timeout: 5000
},
});
export var telegram = new TelegramBot(TELEGRAM_BOT_TOKEN, {polling: true});

export function telegramGetFileURL(filePath) {
return "https://api.telegram.org/file/bot" + TELEGRAM_BOT_TOKEN + "/" + filePath;
};
try {
return "https://api.telegram.org/file/bot" + TELEGRAM_BOT_TOKEN + "/" + filePath;
} catch (err) {
console.log(err.message);
return "";
}
}

export async function telegramGetProfilePic(message) {
try {
var profilePhotos = await telegram.getUserProfilePhotos({ user_id: message.from.id });
} catch (e) {
return "https://telegram.org/img/t_logo.png";
}
if (profilePhotos.total_count > 0) {
var file = await telegram.getFile({ file_id: profilePhotos.photos[0][0].file_id });
return telegramGetFileURL(file.file_path);
} else {
return "https://telegram.org/img/t_logo.png";
var profilePhotos = await telegram.getUserProfilePhotos(message.from.id);

if (profilePhotos.total_count > 0) {
var file = await telegram.getFile(profilePhotos.photos[0][0].file_id);
return telegramGetFileURL(file.file_path);
}
} catch (err) {
console.log(err.message);
}
};

// Send back the Telegram Logo if no profile picture could be fetched
return "https://telegram.org/img/t_logo.png";
}

0 comments on commit 663928d

Please sign in to comment.