Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Commit

Permalink
Renamed and fixed getType in Update object.
Browse files Browse the repository at this point in the history
Added getType in Message object.
  • Loading branch information
Lukasss93 committed Aug 12, 2017
1 parent b5e0303 commit 40052ec
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 98 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Framework for Telegram Bot API",
"license": "MIT",
"type": "project",
"version": "1.4.1",
"version": "1.4.2",
"authors": [
{
"name": "Luca Patera",
Expand All @@ -19,7 +19,8 @@
"autoload": {
"psr-4": {
"TelegramBot\\": "src/",
"TelegramBot\\Types\\": "src/Types/"
"TelegramBot\\Types\\": "src/Types/",
"TelegramBot\\Constants\\": "src/Constants/"
}
}
}
33 changes: 33 additions & 0 deletions src/Constants/MessageTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace TelegramBot\Constants;

class MessageTypes
{
const TEXT = 'text';
const AUDIO = 'audio';
const DOCUMENT = 'document';
const GAME = 'game';
const PHOTO = 'photo';
const STICKER = 'sticker';
const VIDEO = 'video';
const VOICE = 'voice';
const VIDEO_NOTE = 'video_note';
const NEW_CHAT_MEMBERS = 'new_chat_members';
const CONTACT = 'contact';
const LOCATION = 'location';
const VENUE = 'venue';
const NEW_CHAT_MEMBER = 'new_chat_member';
const LEFT_CHAT_MEMBER = 'left_chat_member';
const NEW_CHAT_TITLE = 'new_chat_title';
const NEW_CHAT_PHOTO = 'new_chat_photo';
const DELETE_CHAT_PHOTO = 'delete_chat_photo';
const GROUP_CHAT_CREATED = 'group_chat_created';
const SUPERGROUP_CHAT_CREATED = 'supergroup_chat_created';
const CHANNEL_CHAT_CREATED = 'channel_chat_created';
const MIGRATE_TO_CHAT_ID = 'migrate_to_chat_id';
const MIGRATE_FROM_CHAT_ID = 'migrate_from_chat_id';
const PINNED_MESSAGE = 'pinned_message';
const INVOICE = 'invoice';
const SUCCESSFUL_PAYMENT = 'successful_payment';
}
16 changes: 16 additions & 0 deletions src/Constants/UpdateTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace TelegramBot\Constants;

class UpdateTypes
{
const MESSAGE = 'message';
const EDITED_MESSAGE = 'edited_message';
const CHANNEL_POST = 'channel_post';
const EDITED_CHANNEL_POST = 'edited_channel_post';
const INLINE_QUERY = 'inline_query';
const CHOSEN_INLINE_RESULT = 'chosen_inline_result';
const CALLBACK_QUERY = 'callback_query';
const SHIPPING_QUERY = 'shipping_query';
const PRE_CHECKOUT_QUERY = 'pre_checkout_query';
}
29 changes: 0 additions & 29 deletions src/TelegramUpdateTypes.php

This file was deleted.

116 changes: 116 additions & 0 deletions src/Types/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace TelegramBot\Types;

use TelegramBot\Constants\MessageTypes;

/** This object represents a message. */
class Message
{
Expand Down Expand Up @@ -172,4 +174,118 @@ public function isForwarded()
return !is_null($this->forward_from) || !is_null($this->forward_from_chat);
}

/**
* Return the current message type
* @return false|string
*/
public function getType()
{
if($this->text!==null)
{
return MessageTypes::TEXT;
}
else if($this->audio!==null)
{
return MessageTypes::AUDIO;
}
else if($this->document!==null)
{
return MessageTypes::DOCUMENT;
}
else if($this->game!==null)
{
return MessageTypes::GAME;
}
else if($this->photo!==null)
{
return MessageTypes::PHOTO;
}
else if($this->sticker!==null)
{
return MessageTypes::STICKER;
}
else if($this->video!==null)
{
return MessageTypes::VIDEO;
}
else if($this->voice!==null)
{
return MessageTypes::VOICE;
}
else if($this->video_note!==null)
{
return MessageTypes::VIDEO_NOTE;
}
else if($this->new_chat_members!==null)
{
return MessageTypes::NEW_CHAT_MEMBERS;
}
else if($this->contact!==null)
{
return MessageTypes::CONTACT;
}
else if($this->location!==null)
{
return MessageTypes::LOCATION;
}
else if($this->venue!==null)
{
return MessageTypes::VENUE;
}
else if($this->new_chat_member!==null)
{
return MessageTypes::NEW_CHAT_MEMBER;
}
else if($this->left_chat_member!==null)
{
return MessageTypes::LEFT_CHAT_MEMBER;
}
else if($this->new_chat_title!==null)
{
return MessageTypes::NEW_CHAT_TITLE;
}
else if($this->new_chat_photo!==null)
{
return MessageTypes::NEW_CHAT_PHOTO;
}
else if($this->delete_chat_photo!==null)
{
return MessageTypes::DELETE_CHAT_PHOTO;
}
else if($this->group_chat_created!==null)
{
return MessageTypes::GROUP_CHAT_CREATED;
}
else if($this->supergroup_chat_created!==null)
{
return MessageTypes::SUPERGROUP_CHAT_CREATED;
}
else if($this->channel_chat_created!==null)
{
return MessageTypes::CHANNEL_CHAT_CREATED;
}
else if($this->migrate_to_chat_id!==null)
{
return MessageTypes::MIGRATE_TO_CHAT_ID;
}
else if($this->migrate_from_chat_id!==null)
{
return MessageTypes::MIGRATE_FROM_CHAT_ID;
}
else if($this->pinned_message!==null)
{
return MessageTypes::PINNED_MESSAGE;
}
else if($this->invoice!==null)
{
return MessageTypes::INVOICE;
}
else if($this->successful_payment!==null)
{
return MessageTypes::SUCCESSFUL_PAYMENT;
}

return false;
}

}
86 changes: 19 additions & 67 deletions src/Types/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TelegramBot\Types;

use TelegramBot\TelegramUpdateTypes;
use TelegramBot\Constants\UpdateTypes;

/**
* This object represents an incoming update.
Expand Down Expand Up @@ -49,91 +49,43 @@ class Update
* Return the current update type
* @return false|string
*/
public function getUpdateType()
public function getType()
{
if($this->callback_query!==null)
if($this->message!==null)
{
return TelegramUpdateTypes::CALLBACK_QUERY;
}
else if($this->inline_query!==null)
{
return TelegramUpdateTypes::INLINE_QUERY;
return UpdateTypes::MESSAGE;
}
else if($this->edited_message!==null)
{
return TelegramUpdateTypes::EDITED_MESSAGE;
}
else if($this->message->reply_to_message!==null)
{
return TelegramUpdateTypes::REPLY;
}
else if($this->message->forward_from!==null)
{
return TelegramUpdateTypes::FORWARD_USER;
}
else if($this->message->forward_from_chat!==null)
{
return TelegramUpdateTypes::FORWARD_CHAT;
}
else if($this->message->text!==null)
{
return TelegramUpdateTypes::MESSAGE;
}
else if($this->message->game!==null)
{
return TelegramUpdateTypes::GAME;
return UpdateTypes::EDITED_MESSAGE;
}
else if($this->message->sticker!==null)
else if($this->channel_post!==null)
{
return TelegramUpdateTypes::STICKER;
return UpdateTypes::CHANNEL_POST;
}
else if($this->message->photo!==null)
else if($this->edited_channel_post!==null)
{
return TelegramUpdateTypes::PHOTO;
return UpdateTypes::EDITED_CHANNEL_POST;
}
else if($this->message->video!==null)
{
return TelegramUpdateTypes::VIDEO;
}
else if($this->message->audio!==null)
{
return TelegramUpdateTypes::AUDIO;
}
else if($this->message->voice!==null)
{
return TelegramUpdateTypes::VOICE;
}
else if($this->message->contact!==null)
{
return TelegramUpdateTypes::CONTACT;
}
else if($this->message->document!==null)
{
return TelegramUpdateTypes::DOCUMENT;
}
else if($this->message->location!==null)
{
return TelegramUpdateTypes::LOCATION;
}
else if($this->message->venue!==null)
else if($this->inline_query!==null)
{
return TelegramUpdateTypes::VENUE;
return UpdateTypes::INLINE_QUERY;
}
else if($this->message->video_note!==null)
else if($this->chosen_inline_result!==null)
{
return TelegramUpdateTypes::VIDEO_NOTE;
return UpdateTypes::CHOSEN_INLINE_RESULT;
}
else if($this->message->pinned_message!==null)
else if($this->callback_query!==null)
{
return TelegramUpdateTypes::PINNED_MESSAGE;
return UpdateTypes::CALLBACK_QUERY;
}
else if($this->message->invoice!==null)
else if($this->shipping_query!==null)
{
return TelegramUpdateTypes::INVOICE;
return UpdateTypes::SHIPPING_QUERY;
}
else if($this->message->successful_payment!==null)
else if($this->pre_checkout_query!==null)
{
return TelegramUpdateTypes::SUCCESSFUL_PAYMENT;
return UpdateTypes::PRE_CHECKOUT_QUERY;
}

return false;
Expand Down

0 comments on commit 40052ec

Please sign in to comment.