add: send read messsages

master
user 1 year ago
parent 337ebb2cbb
commit c3f54b0b1a

@ -1,35 +1,79 @@
import { Client } from 'tdl'; import { Client } from "tdl";
import { TDLib } from 'tdl-tdlib-addon'; import { TDLib } from "tdl-tdlib-addon";
import path from 'path'; import path from "path";
import dotenv from 'dotenv' import dotenv from "dotenv";
dotenv.config() dotenv.config();
const __dirname = path.dirname(new URL(import.meta.url).pathname); const __dirname = path.dirname(new URL(import.meta.url).pathname);
function onUpdate(update) { function onUpdate(update) {
console.log('UPDATE HERE', 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')), { const client = new Client(new TDLib(path.join(__dirname, "libtdjson.so")), {
apiId: process.env.APP_ID, apiId: process.env.APP_ID,
apiHash: process.env.APP_HASH apiHash: process.env.APP_HASH,
}) });
client.login() const savedMessages = process.env.SAVED_MESSAGES_ID;
client.on('update', onUpdate) client.login();
client.on('error', console.error)
async function main(){ client.on("update", onUpdate);
client.on("error", console.error);
const chats = await client.invoke({ async function sendText() {
_: 'getChats', //👻
chat_list: { _: 'chatListMain' }, await client
limit: 4000 .invoke({
_: "sendMessage",
chat_id: savedMessages,
input_message_content: {
_: "inputMessageText",
text: {
_: "formattedText",
text: "a",
},
},
}) })
.then(console.log("Message sent"))
console.log('current chats', chats) .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();

Loading…
Cancel
Save