Created
January 2, 2020 16:02
-
-
Save painor/a466dcf937b03c9c7a09400fdda411c1 to your computer and use it in GitHub Desktop.
Small login + send message script with gramJS
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 readline = require("readline") | |
const { ResolveUsernameRequest } = require("telegram/gramjs/tl/functions/contacts") | |
const { SendMessageRequest } = require("telegram/gramjs/tl/functions/messages") | |
const { TelegramClient} = require('telegram/gramjs') | |
const apiId = 12345689 | |
const apiHash = "123456789abcdfgh" | |
const { ConnectionTCPFull } = require('telegram/gramjs/network') | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}) | |
const client = new TelegramClient("session", apiId, apiHash, { connection: ConnectionTCPFull }) | |
async function codeCallback() { | |
return new Promise((resolve => { | |
rl.question('Input the code you received : ', (answer) => { | |
resolve(answer) | |
}) | |
})) | |
} | |
async function passwordCallback() { | |
return new Promise((resolve => { | |
rl.question('please enter your password :', (answer) => { | |
resolve(answer) | |
}) | |
})) | |
} | |
async function phoneCallback() { | |
return new Promise((resolve => { | |
rl.question('Please enter your phone number : ', (answer) => { | |
resolve(answer) | |
}) | |
})) | |
} | |
(async function f() { | |
await client.start({ | |
phone: phoneCallback, | |
code: codeCallback, | |
password: passwordCallback, | |
}) | |
const peer = await client.invoke(new ResolveUsernameRequest({ | |
username: "username", | |
})) | |
console.log(peer) | |
await client.invoke(new SendMessageRequest({ | |
peer: peer, | |
message: 'hello' | |
})) | |
console.log("all done") | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment