GramJS provides two firendly methods for getting messages.
GetMessages which returns a totalList (a normal array with a .total attribute) of messages and iterMessages which returns a generator.
(async () => {
const client = new TelegramClient(new StringSession(stringSession), apiId, apiHash, {})
await client.connect();
const msgs = await client.getMessages("me", {
limit: 10,
});
console.log("the total number of msgs are", msgs.total);
console.log("what we got is ", msgs.length);
for (const msg of msgs) {
//console.log("msg is",msg); // this line is very verbose but helpful for debugging
console.log("msg text is : ", msg.text);
}
})();
The return type is not Api.Message but is the custom type custom.Message