More message detection#37
Conversation
|
OK, so this PR is just a very small tweak but I thought I'd explain why I needed/wanted it. We have two functions in API. isMessageType() Both currently require an UPDATE object to see what type of message we have. However, I've found a use case in which I actually needed to detect the message type from a MESSAGE object. Basically, when you send a message (eg a photo) with Telegram::sendPhoto you always get a MESSAGE object as the return. In my program, I fire an event after I send a message, and I pass the MESSAGE object through to the event. Now when my listener listens for a "sent message event", it receives the MESSAGE object. At this stage, I do different things depending on the type of message that was sent. To work that out, I wanted to use the detectMessageType() function, only I couldn't because it needed an UPDATE object instead. So, I tweaked the two functions to allow them to accept EITHER object and return the correct reply. Of course I could create many events like photoMessageSent, videoMessageSent etc etc and listen for each one, but that was going to add a lot more code, rather than listen for a generic messageSent event and do a quick detection afterwards. Anyway, I hope that makes sense. It's only a few lines of code changed, and I have tested and it works well with bothe UPDATE and MESSAGE objects so no BC problems. By the way, I'm still not sure how to do a PR that doesn't make you have to do a merge commit. I think you said something about creating a branch and doing it from there. So that's what I've done. If that's wrong, don't merge it - tell me what to do and I'll do it properly. I would like to learn the correct way. |
See below