You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.8 KiB
JavaScript
80 lines
1.8 KiB
JavaScript
import { Client } from "tdl";
|
|
import { TDLib } from "tdl-tdlib-addon";
|
|
import path from "path";
|
|
import dotenv from "dotenv";
|
|
|
|
dotenv.config();
|
|
const __dirname = path.dirname(new URL(import.meta.url).pathname);
|
|
|
|
function onUpdate(update) {
|
|
if (update.chat_id == "91956172") {
|
|
const last_msg = update.last_message.content.text.text;
|
|
console.log(last_msg);
|
|
}
|
|
//console.log('Saved messages', update.last_message.content.text.text)
|
|
}
|
|
|
|
const client = new Client(new TDLib(path.join(__dirname, "libtdjson.so")), {
|
|
apiId: process.env.APP_ID,
|
|
apiHash: process.env.APP_HASH,
|
|
});
|
|
|
|
const savedMessages = process.env.SAVED_MESSAGES_ID;
|
|
|
|
client.login();
|
|
|
|
client.on("update", onUpdate);
|
|
client.on("error", console.error);
|
|
|
|
async function sendText() {
|
|
//👻
|
|
await client
|
|
.invoke({
|
|
_: "sendMessage",
|
|
chat_id: savedMessages,
|
|
input_message_content: {
|
|
_: "inputMessageText",
|
|
text: {
|
|
_: "formattedText",
|
|
text: "a",
|
|
},
|
|
},
|
|
})
|
|
.then(console.log("Message sent"))
|
|
.catch((error) => console.error(error));
|
|
}
|
|
|
|
async function showSavedMessages() {
|
|
let imlooping = true
|
|
let msgTxt = ''
|
|
while (imlooping) {
|
|
await client
|
|
.invoke({
|
|
_: "getChat",
|
|
chat_id: savedMessages,
|
|
})
|
|
.then((message) => {
|
|
const msgContent = message.last_message.content
|
|
msgTxt = ''
|
|
if(msgContent._ == 'messageText') {
|
|
msgTxt = msgContent.text.text
|
|
} else {
|
|
console.log('message type not detected')
|
|
}
|
|
})
|
|
.catch((error) => {
|
|
console.error(error, savedMessages);
|
|
imlooping = false
|
|
});
|
|
}
|
|
console.log(msgTxt)
|
|
}
|
|
|
|
async function main() {
|
|
showSavedMessages();
|
|
sendText();
|
|
console.log("Logging chats");
|
|
}
|
|
|
|
main();
|