Comments (5)
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 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.
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.
GetAllChats return only your chats, not users.
Use Messages_GetAllDialogs to get the chats AND users you're chatting with
from wtelegramclient.
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)
- Client.User field is not updated during the session, can be harmful HOT 2
- Logout Active Session : Account_GetAuthorizations return 0 hash for active session HOT 4
- Unable to cast object of type 'TL.UserEmpty' to type 'TL.User'. HOT 3
- Interrupted login (resumed/asynchronous) HOT 5
- The method address is different HOT 3
- Cannot find type for ctor #38116ee0 HOT 2
- Stack overflow on poison message HOT 5
- QR Support HOT 6
- Session serialization error HOT 2
- Getting Message History with min_id HOT 2
- Contact for specific questions ? HOT 1
- Issue using Stream for saving session HOT 5
- Some properties are only private HOT 1
- Object of type 'TL.PeerChannel' cannot be converted to type 'TL.MessageFwdHeader'. HOT 3
- I always get updateDeleteMessages. HOT 2
- An exception occured in the reactor: WTelegram.WTException: Cannot find type for ctor #whatever after upgrading to v4.x HOT 3
- contacts.getLocated HOT 1
- how to get data for miniapp? HOT 1
- voip support HOT 1
- fetching messages sent to bot download them
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wtelegramclient.