I’m working on an telegram anti-flood bot, so I created a simple one, save the text and sender ID in a JSON when a message is sent, when another message is sent, check if both are the same and if so, deletes the message; however the method doesn’t work sometimes and deletes a different message (eg.: 2 different images without a caption are sent by a user quickly, the second image will be deleted), so I wanted to save all JSON excluding specific elements (like message id and date), because they’re always different, so how can i do that?
Here is a JSON message for examples:
{
message_id: 0,
from: {
id: 0,
is_bot: false,
first_name: 'John',
last_name: 'Doe',
username: 'JohnDoe',
language_code: 'en-us'
},
chat: { id: 0, title: 'Cool Group.', type: 'group' },
date: 12345,
text: 'Test Message.'
}
2
Answers
First store your Object in some variable than delete key-value which you want to exclude.
It may be overkill, but you could make the structure which you expect, with fallback defaults, then merge in the incoming object, ignoring any properties not in the schema or of a different type… call it strict merge.