Created
January 13, 2017 05:49
-
-
Save par6n/d7fc6f4d06ed4380888a3001c348ac9d to your computer and use it in GitHub Desktop.
@Link4FileBot
This file contains hidden or 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
const Telegraf = require( 'telegraf' ), | |
request = require( 'request' ), | |
Token = 'TOKEN HERE', | |
currentUsers = {}, | |
messages = {}, | |
Bot = new Telegraf( Token ); | |
Bot.command( 'start', ( ctx ) => { | |
ctx.replyWithHTML( `<b>Send/Forward me your files to get the direct link for it.</b> | |
Powered by @pwrtelegram` ); | |
} ); | |
Bot.on( 'photo', ( ctx ) => { | |
ctx.reply( 'Seriously? Send me a file or video or audio.' ); | |
} ); | |
Bot.on( [ 'document', 'video', 'audio', 'voice' ], ( ctx ) => { | |
if ( currentUsers[ ctx.from.id ] ) { | |
ctx.reply( 'Please wait while the other file is being downloaded...' ); | |
return; | |
} | |
var msg = ctx.update.message, file_id; | |
if ( msg.document ) file_id = msg.document.file_id; | |
if ( msg.video ) file_id = msg.video.file_id; | |
if ( msg.audio ) file_id = msg.audio.file_id; | |
if ( msg.voice ) file_id = msg.voice.file_id; | |
if ( !file_id ) { | |
ctx.reply( `Invalid file identifier` ); | |
return; | |
} | |
ctx.reply( 'Please wait. depending on your file size, it might take a while.', { reply_to_message_id: msg.message_id } ).then( ( sent ) => { | |
messages[ ctx.from.id ] = sent.message_id; | |
} ); | |
currentUsers[ ctx.from.id ] = true; | |
request( `https://api.pwrtelegram.xyz/bot${Token}/getFile?file_id=${file_id}`, ( err, resp, body ) => { | |
var data = JSON.parse( body ); | |
currentUsers[ ctx.from.id ] = false; | |
ctx.telegram.callApi( 'editMessageText', { | |
chat_id: ctx.chat.id, | |
message_id: messages[ ctx.from.id ], | |
parse_mode: 'HTML', | |
text: `✅ Here is your file: <a href="https://storage.pwrtelegram.xyz/${data.result.file_path}">Download File</a>` | |
} ); | |
} ); | |
} ); | |
Bot.startPolling(); |
This file contains hidden or 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
{ | |
"name": "link4file", | |
"version": "1.0.0", | |
"description": "@Link4File", | |
"main": "index.js", | |
"author": "EhsaanF", | |
"license": "ISC", | |
"dependencies": { | |
"request": "^2.79.0", | |
"telegraf": "^3.6.4" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment