Skip to content

More message detection#37

Merged
irazasyed merged 2 commits into
irazasyed:masterfrom
jonnywilliamson:moreMessageDetection
Sep 19, 2015
Merged

More message detection#37
irazasyed merged 2 commits into
irazasyed:masterfrom
jonnywilliamson:moreMessageDetection

Conversation

@jonnywilliamson
Copy link
Copy Markdown
Contributor

See below

@jonnywilliamson
Copy link
Copy Markdown
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