Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
SESSION = "1AQAOMTQ5LjE1NC4xNzUuNTEBuwFGaJfCol90zf7QZ5y8Usxu0FDIHpJDrOLlvQjxmq0q6eQwqOGcpLMzfUXadOcDXBg0XpcnXYJc6Zsx8anHqpe/+nmz21sFKKTHtH+jmZZ9k/+eO9d1U8duJjubBm7uWrkWt/sV1jRaYOcfK0JqsBYjebxPxeTP/16kn75q4EbIliW+GKcAObwRtx5pshjHKRvwjVeZ+XESjeL42/GC7SH/5NF8SrN1KpUqf+bQFerwCJrIlqROCQWO5X/pkYv1nvl5fNtp2i8nu6FXjJGGdjlFyESLTMWA5PVgy9mN5ee84KiT58MhuJOVMCtiNlkbGMKIZQl2f3KqQOeatJTUDhI=
"
"

# This was inserted by `prisma init`:
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="postgresql://postgres:postgres@localhost:10002"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
# Keep environment variables out of version control
.env
58 changes: 35 additions & 23 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Api, TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";
import { PrismaClient } from "@prisma/client";

import readline from "readline";

const prisma = new PrismaClient();
const apiId = 27354197;
const apiHash = "de1f90fc8d3b7ae2c2ec6c7463086757";
const stringSession = new StringSession(
Expand Down Expand Up @@ -36,31 +39,40 @@ const rl = readline.createInterface({
console.log("You should now be connected.");
console.log(client.session.save()); // Save this string to avoid logging in again
await client.sendMessage("me", { message: "Hello!" });
const result = await client.invoke(
new Api.messages.GetHistory({
offsetId: 1090, //change offsets to get every message
peer: -1002083186778,
limit: 100,
})
);

console.log(result.messages.map((element) => element.message));
})();

//peer
//peerUser, peerChat(group), peerChannel (channel/supergroup)
//https://core.telegram.org/api/folders
//A chat is a type of peer
//console.log(result);

/*
let helper = [];
for (let i = 0; i < 10000; i += 100) {
console.log("looped");
helper = await client.invoke(
new Api.messages.GetHistory({
offsetId: i, //change offsets to get every message
peer: -1002083186778,
limit: 150,
})
);

const result = await client.invoke(
new Api.messages.GetHistory({
peer: -1002083186778,
limit: 100,
})
);
const prep = helper.messages.filter((element) => element.fromId != null);

console.log(result.messages.map((element) => element.message));
const idDateMessage = prep.map((element) =>
element.message != null
? [element.fromId.userId.value, element.date, element.message]
: [element.fromId.userId.value, element.date, "message missing"]
);

*/
for (let j = 0; j < idDateMessage.length; j++) {
await prisma.message.create({
data: {
sender: idDateMessage[j][0],
time: idDateMessage[j][1],
message: idDateMessage[j][2],
},
});
}
}
prisma.message.findMany({}).then((response) => console.log(response));
async () => {
await prisma.$disconnect();
};
})();
Loading