add: send read messsages

master
user 1 year ago
parent 337ebb2cbb
commit c3f54b0b1a

@ -1,35 +1,79 @@
import { Client } from 'tdl';
import { TDLib } from 'tdl-tdlib-addon';
import path from 'path';
import dotenv from 'dotenv'
import { Client } from "tdl";
import { TDLib } from "tdl-tdlib-addon";
import path from "path";
import dotenv from "dotenv";
dotenv.config()
dotenv.config();
const __dirname = path.dirname(new URL(import.meta.url).pathname);
function onUpdate(update){
console.log('UPDATE HERE', update)
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')), {
const client = new Client(new TDLib(path.join(__dirname, "libtdjson.so")), {
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.on('error', console.error)
client.login();
async function main(){
client.on("update", onUpdate);
client.on("error", console.error);
const chats = await client.invoke({
_: 'getChats',
chat_list: { _: 'chatListMain' },
limit: 4000
})
console.log('current chats', chats)
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();

Loading…
Cancel
Save