GithubHelp home page GithubHelp logo

Comments (5)

wiz0u avatar wiz0u commented on June 7, 2024

if I understand your question correctly, you want to fetch the messages you exchanged with a bot.

A bot IS a user (just with flag bot and usually a username ending with "bot"), so it's the same as with a user.

from wtelegramclient.

github-actions avatar github-actions commented on June 7, 2024

Github Issues should be used only for problems with the library itself.
For questions about Telegram API usage, you can search the API official documentation or click here to ask your question on StackOverflow so the whole community can help and benefit.

from wtelegramclient.

400ochkov avatar 400ochkov commented on June 7, 2024

if I understand your question correctly, you want to fetch the messages you exchanged with a bot.

A bot IS a user (just with flag bot and usually a username ending with "bot"), so it's the same as with a user.

I took this code from samples, but if i set user id in chats.chats[1234567890] i faced error "System.Collections.Generic.KeyNotFoundException: "The given key 'xxx' was not present in the dictionary.""
But if set chat id from everything works good

So may be there is another way to fetch messages from users (chat with users) or bots?

var chats = await client.Messages_GetAllChats(); InputPeer peer = chats.chats[1234567890]; // the chat (or User) we want for (int offset_id = 0; ;) { var messages = await client.Messages_GetHistory(peer, offset_id); if (messages.Messages.Length == 0) break; foreach (var msgBase in messages.Messages) { var from = messages.UserOrChat(msgBase.From ?? msgBase.Peer); // from can be User/Chat/Channel if (msgBase is Message msg) Console.WriteLine($"{from}> {msg.message} {msg.media}"); else if (msgBase is MessageService ms) Console.WriteLine($"{from} [{ms.action.GetType().Name[13..]}]"); } offset_id = messages.Messages[^1].ID; }

from wtelegramclient.

wiz0u avatar wiz0u commented on June 7, 2024

GetAllChats return only your chats, not users.
Use Messages_GetAllDialogs to get the chats AND users you're chatting with

from wtelegramclient.

400ochkov avatar 400ochkov commented on June 7, 2024

GetAllChats return only your chats, not users. Use Messages_GetAllDialogs to get the chats AND users you're chatting with

yes, I can get users id via this method, but how to fetch message history with user id?
I tried code
var dialogs = await Client.Messages_GetAllDialogs();
InputPeer peer = dialogs.chats[123456789];
for (int offset_id = 0; ;)
{
var messages = await Client.Messages_GetHistory(peer, offset_id);
if (messages.Messages.Length == 0) break;
foreach (var msgBase in messages.Messages)
{
var from = messages.UserOrChat(msgBase.From ?? msgBase.Peer); // from can be User/Chat/Channel
if (msgBase is Message msg)
Console.WriteLine($"{from}> {msg.message} {msg.date}");
else if (msgBase is MessageService ms)
Console.WriteLine($"{from} [{ms.action.GetType().Name[13..]}]");
}
offset_id = messages.Messages[^1].ID;
}

But faced some error as in my previous post.

Also tried change InputPeer peer = dialogs.chats[123456789]; to InputPeer peer = dialogs.dialogs[123456789];, but dialogs.dialogs is not dictionary so doesnt work in this way

How should I set peer variable with user id in order to fetch messages after that?

from wtelegramclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.