Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More message detection #37

Merged
merged 2 commits into from
Sep 19, 2015
Merged

More message detection #37

merged 2 commits into from
Sep 19, 2015

Conversation

jonnywilliamson
Copy link
Contributor

See below

@jonnywilliamson
Copy link
Contributor Author

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()
detectMessageType()

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants