-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'SebaUbuntu:master' into development
- Loading branch information
Showing
5 changed files
with
1,143 additions
and
577 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} |
Oops, something went wrong.