From 7957fa96235818274332be2602e153d0dc374032 Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Thu, 14 Jan 2016 01:14:53 +0100 Subject: [PATCH] Migrate from examples project --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 35 + .idea/.name | 1 + .idea/compiler.xml | 32 + .idea/copyright/profiles_settings.xml | 3 + .idea/encodings.xml | 7 + .idea/inspectionProfiles/Project_Default.xml | 49 ++ .../inspectionProfiles/profiles_settings.xml | 7 + .idea/jsLinters/jshint.xml | 71 ++ ...jackson_core_jackson_annotations_2_5_4.xml | 13 + ...terxml_jackson_core_jackson_core_2_5_4.xml | 13 + ...ml_jackson_core_jackson_databind_2_5_4.xml | 13 + ...jackson_jaxrs_jackson_jaxrs_base_2_5_4.xml | 13 + ...axrs_jackson_jaxrs_json_provider_2_5_4.xml | 13 + ..._jackson_module_jaxb_annotations_2_5_4.xml | 13 + ...ven__com_sun_jersey_jersey_bundle_1_19.xml | 13 + ...Maven__com_sun_jersey_jersey_core_1_19.xml | 13 + ...n__com_sun_jersey_jersey_grizzly2_1_19.xml | 13 + ...un_jersey_jersey_grizzly2_servlet_1_19.xml | 13 + ...ven__com_sun_jersey_jersey_server_1_19.xml | 13 + ...en__com_sun_jersey_jersey_servlet_1_19.xml | 13 + ...Maven__commons_codec_commons_codec_1_9.xml | 13 + ...n__commons_logging_commons_logging_1_2.xml | 13 + ...ax_annotation_javax_annotation_api_1_2.xml | 13 + ..._javax_servlet_javax_servlet_api_3_0_1.xml | 13 + ..._validation_validation_api_1_1_0_Final.xml | 13 + ...ven__javax_ws_rs_javax_ws_rs_api_2_0_1.xml | 13 + .../Maven__javax_ws_rs_jsr311_api_1_1_1.xml | 13 + ...apache_httpcomponents_httpclient_4_5_1.xml | 13 + ...g_apache_httpcomponents_httpcore_4_4_3.xml | 13 + ...g_apache_httpcomponents_httpmime_4_5_1.xml | 13 + ...sfish_grizzly_grizzly_framework_2_3_22.xml | 13 + ..._glassfish_grizzly_grizzly_http_2_3_22.xml | 13 + ...ish_grizzly_grizzly_http_server_2_3_22.xml | 13 + ...sh_grizzly_grizzly_http_servlet_2_2_16.xml | 13 + ...ernal_aopalliance_repackaged_2_4_0_b31.xml | 13 + ...sh_hk2_external_javax_inject_2_4_0_b31.xml | 13 + ...n__org_glassfish_hk2_hk2_api_2_4_0_b31.xml | 13 + ...rg_glassfish_hk2_hk2_locator_2_4_0_b31.xml | 13 + ..._org_glassfish_hk2_hk2_utils_2_4_0_b31.xml | 13 + ...ssfish_hk2_osgi_resource_locator_1_0_1.xml | 13 + ...y_bundles_repackaged_jersey_guava_2_21.xml | 13 + ...rs_jersey_container_grizzly2_http_2_21.xml | 13 + ...assfish_jersey_core_jersey_client_2_21.xml | 13 + ...assfish_jersey_core_jersey_common_2_21.xml | 13 + ...assfish_jersey_core_jersey_server_2_21.xml | 13 + ...ersey_ext_jersey_entity_filtering_2_21.xml | 13 + ...sh_jersey_media_jersey_media_jaxb_2_21.xml | 13 + ...y_media_jersey_media_json_jackson_2_21.xml | 13 + ...ven__org_javassist_javassist_3_18_1_GA.xml | 13 + .../Maven__org_json_json_20141113.xml | 13 + .idea/misc.xml | 77 ++ .idea/modules.xml | 8 + .idea/resourceBundles.xml | 11 + .idea/uiDesigner.xml | 124 ++++ .idea/vcs.xml | 6 + BotAPi.iml | 57 ++ LICENSE | 675 ++++++++++++++++++ README.md | 51 ++ eclipse configuration.md | 27 + pom.xml | 146 ++++ src/.DS_Store | Bin 0 -> 6148 bytes src/main/.DS_Store | Bin 0 -> 6148 bytes src/main/java/.DS_Store | Bin 0 -> 6148 bytes src/main/java/org/telegram/SenderHelper.java | 287 ++++++++ .../telegram/api/interfaces/BotApiObject.java | 13 + .../org/telegram/api/interfaces/IToJson.java | 18 + .../api/methods/AnswerInlineQuery.java | 138 ++++ .../telegram/api/methods/BotApiMethod.java | 28 + .../org/telegram/api/methods/Constants.java | 11 + .../telegram/api/methods/ForwardMessage.java | 92 +++ .../org/telegram/api/methods/GetFile.java | 74 ++ .../java/org/telegram/api/methods/GetMe.java | 50 ++ .../org/telegram/api/methods/GetUpdates.java | 77 ++ .../api/methods/GetUserProfilePhotos.java | 102 +++ .../org/telegram/api/methods/SendAudio.java | 104 +++ .../telegram/api/methods/SendChatAction.java | 86 +++ .../telegram/api/methods/SendDocument.java | 76 ++ .../telegram/api/methods/SendLocation.java | 123 ++++ .../org/telegram/api/methods/SendMessage.java | 148 ++++ .../org/telegram/api/methods/SendPhoto.java | 87 +++ .../org/telegram/api/methods/SendSticker.java | 76 ++ .../org/telegram/api/methods/SendVideo.java | 98 +++ .../org/telegram/api/methods/SendVoice.java | 31 + .../org/telegram/api/methods/SetWebhook.java | 39 + .../java/org/telegram/api/objects/Audio.java | 134 ++++ .../java/org/telegram/api/objects/Chat.java | 129 ++++ .../api/objects/ChosenInlineQuery.java | 66 ++ .../org/telegram/api/objects/Contact.java | 68 ++ .../org/telegram/api/objects/Document.java | 119 +++ .../java/org/telegram/api/objects/File.java | 86 +++ .../api/objects/ForceReplyKeyboard.java | 94 +++ .../org/telegram/api/objects/InlineQuery.java | 76 ++ .../api/objects/InlineQueryResult.java | 13 + .../api/objects/InlineQueryResultArticle.java | 233 ++++++ .../api/objects/InlineQueryResultGif.java | 213 ++++++ .../objects/InlineQueryResultMpeg4Gif.java | 214 ++++++ .../api/objects/InlineQueryResultPhoto.java | 249 +++++++ .../api/objects/InlineQueryResultVideo.java | 245 +++++++ .../org/telegram/api/objects/Location.java | 66 ++ .../org/telegram/api/objects/Message.java | 528 ++++++++++++++ .../org/telegram/api/objects/PhotoSize.java | 96 +++ .../telegram/api/objects/ReplyKeyboard.java | 13 + .../api/objects/ReplyKeyboardHide.java | 88 +++ .../api/objects/ReplyKeyboardMarkup.java | 156 ++++ .../org/telegram/api/objects/Sticker.java | 73 ++ .../java/org/telegram/api/objects/Update.java | 104 +++ .../java/org/telegram/api/objects/User.java | 84 +++ .../api/objects/UserProfilePhotos.java | 90 +++ .../java/org/telegram/api/objects/Video.java | 142 ++++ .../java/org/telegram/api/objects/Voice.java | 99 +++ .../java/org/telegram/services/BotLogger.java | 348 +++++++++ .../updateshandlers/SentCallback.java | 26 + .../updateshandlers/UpdatesCallback.java | 24 + .../telegram/updatesreceivers/RestApi.java | 52 ++ .../updatesreceivers/UpdatesThread.java | 141 ++++ .../telegram/updatesreceivers/Webhook.java | 83 +++ 117 files changed, 7843 insertions(+) create mode 100644 .DS_Store create mode 100644 .gitignore create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/jsLinters/jshint.xml create mode 100644 .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_5_4.xml create mode 100644 .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_5_4.xml create mode 100644 .idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_5_4.xml create mode 100644 .idea/libraries/Maven__com_fasterxml_jackson_jaxrs_jackson_jaxrs_base_2_5_4.xml create mode 100644 .idea/libraries/Maven__com_fasterxml_jackson_jaxrs_jackson_jaxrs_json_provider_2_5_4.xml create mode 100644 .idea/libraries/Maven__com_fasterxml_jackson_module_jackson_module_jaxb_annotations_2_5_4.xml create mode 100644 .idea/libraries/Maven__com_sun_jersey_jersey_bundle_1_19.xml create mode 100644 .idea/libraries/Maven__com_sun_jersey_jersey_core_1_19.xml create mode 100644 .idea/libraries/Maven__com_sun_jersey_jersey_grizzly2_1_19.xml create mode 100644 .idea/libraries/Maven__com_sun_jersey_jersey_grizzly2_servlet_1_19.xml create mode 100644 .idea/libraries/Maven__com_sun_jersey_jersey_server_1_19.xml create mode 100644 .idea/libraries/Maven__com_sun_jersey_jersey_servlet_1_19.xml create mode 100644 .idea/libraries/Maven__commons_codec_commons_codec_1_9.xml create mode 100644 .idea/libraries/Maven__commons_logging_commons_logging_1_2.xml create mode 100644 .idea/libraries/Maven__javax_annotation_javax_annotation_api_1_2.xml create mode 100644 .idea/libraries/Maven__javax_servlet_javax_servlet_api_3_0_1.xml create mode 100644 .idea/libraries/Maven__javax_validation_validation_api_1_1_0_Final.xml create mode 100644 .idea/libraries/Maven__javax_ws_rs_javax_ws_rs_api_2_0_1.xml create mode 100644 .idea/libraries/Maven__javax_ws_rs_jsr311_api_1_1_1.xml create mode 100644 .idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_1.xml create mode 100644 .idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_3.xml create mode 100644 .idea/libraries/Maven__org_apache_httpcomponents_httpmime_4_5_1.xml create mode 100644 .idea/libraries/Maven__org_glassfish_grizzly_grizzly_framework_2_3_22.xml create mode 100644 .idea/libraries/Maven__org_glassfish_grizzly_grizzly_http_2_3_22.xml create mode 100644 .idea/libraries/Maven__org_glassfish_grizzly_grizzly_http_server_2_3_22.xml create mode 100644 .idea/libraries/Maven__org_glassfish_grizzly_grizzly_http_servlet_2_2_16.xml create mode 100644 .idea/libraries/Maven__org_glassfish_hk2_external_aopalliance_repackaged_2_4_0_b31.xml create mode 100644 .idea/libraries/Maven__org_glassfish_hk2_external_javax_inject_2_4_0_b31.xml create mode 100644 .idea/libraries/Maven__org_glassfish_hk2_hk2_api_2_4_0_b31.xml create mode 100644 .idea/libraries/Maven__org_glassfish_hk2_hk2_locator_2_4_0_b31.xml create mode 100644 .idea/libraries/Maven__org_glassfish_hk2_hk2_utils_2_4_0_b31.xml create mode 100644 .idea/libraries/Maven__org_glassfish_hk2_osgi_resource_locator_1_0_1.xml create mode 100644 .idea/libraries/Maven__org_glassfish_jersey_bundles_repackaged_jersey_guava_2_21.xml create mode 100644 .idea/libraries/Maven__org_glassfish_jersey_containers_jersey_container_grizzly2_http_2_21.xml create mode 100644 .idea/libraries/Maven__org_glassfish_jersey_core_jersey_client_2_21.xml create mode 100644 .idea/libraries/Maven__org_glassfish_jersey_core_jersey_common_2_21.xml create mode 100644 .idea/libraries/Maven__org_glassfish_jersey_core_jersey_server_2_21.xml create mode 100644 .idea/libraries/Maven__org_glassfish_jersey_ext_jersey_entity_filtering_2_21.xml create mode 100644 .idea/libraries/Maven__org_glassfish_jersey_media_jersey_media_jaxb_2_21.xml create mode 100644 .idea/libraries/Maven__org_glassfish_jersey_media_jersey_media_json_jackson_2_21.xml create mode 100644 .idea/libraries/Maven__org_javassist_javassist_3_18_1_GA.xml create mode 100644 .idea/libraries/Maven__org_json_json_20141113.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/resourceBundles.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 BotAPi.iml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 eclipse configuration.md create mode 100644 pom.xml create mode 100644 src/.DS_Store create mode 100644 src/main/.DS_Store create mode 100644 src/main/java/.DS_Store create mode 100644 src/main/java/org/telegram/SenderHelper.java create mode 100644 src/main/java/org/telegram/api/interfaces/BotApiObject.java create mode 100644 src/main/java/org/telegram/api/interfaces/IToJson.java create mode 100644 src/main/java/org/telegram/api/methods/AnswerInlineQuery.java create mode 100644 src/main/java/org/telegram/api/methods/BotApiMethod.java create mode 100644 src/main/java/org/telegram/api/methods/Constants.java create mode 100644 src/main/java/org/telegram/api/methods/ForwardMessage.java create mode 100644 src/main/java/org/telegram/api/methods/GetFile.java create mode 100644 src/main/java/org/telegram/api/methods/GetMe.java create mode 100644 src/main/java/org/telegram/api/methods/GetUpdates.java create mode 100644 src/main/java/org/telegram/api/methods/GetUserProfilePhotos.java create mode 100644 src/main/java/org/telegram/api/methods/SendAudio.java create mode 100644 src/main/java/org/telegram/api/methods/SendChatAction.java create mode 100644 src/main/java/org/telegram/api/methods/SendDocument.java create mode 100644 src/main/java/org/telegram/api/methods/SendLocation.java create mode 100644 src/main/java/org/telegram/api/methods/SendMessage.java create mode 100644 src/main/java/org/telegram/api/methods/SendPhoto.java create mode 100644 src/main/java/org/telegram/api/methods/SendSticker.java create mode 100644 src/main/java/org/telegram/api/methods/SendVideo.java create mode 100644 src/main/java/org/telegram/api/methods/SendVoice.java create mode 100644 src/main/java/org/telegram/api/methods/SetWebhook.java create mode 100644 src/main/java/org/telegram/api/objects/Audio.java create mode 100644 src/main/java/org/telegram/api/objects/Chat.java create mode 100644 src/main/java/org/telegram/api/objects/ChosenInlineQuery.java create mode 100644 src/main/java/org/telegram/api/objects/Contact.java create mode 100644 src/main/java/org/telegram/api/objects/Document.java create mode 100644 src/main/java/org/telegram/api/objects/File.java create mode 100644 src/main/java/org/telegram/api/objects/ForceReplyKeyboard.java create mode 100644 src/main/java/org/telegram/api/objects/InlineQuery.java create mode 100644 src/main/java/org/telegram/api/objects/InlineQueryResult.java create mode 100644 src/main/java/org/telegram/api/objects/InlineQueryResultArticle.java create mode 100644 src/main/java/org/telegram/api/objects/InlineQueryResultGif.java create mode 100644 src/main/java/org/telegram/api/objects/InlineQueryResultMpeg4Gif.java create mode 100644 src/main/java/org/telegram/api/objects/InlineQueryResultPhoto.java create mode 100644 src/main/java/org/telegram/api/objects/InlineQueryResultVideo.java create mode 100644 src/main/java/org/telegram/api/objects/Location.java create mode 100644 src/main/java/org/telegram/api/objects/Message.java create mode 100644 src/main/java/org/telegram/api/objects/PhotoSize.java create mode 100644 src/main/java/org/telegram/api/objects/ReplyKeyboard.java create mode 100644 src/main/java/org/telegram/api/objects/ReplyKeyboardHide.java create mode 100644 src/main/java/org/telegram/api/objects/ReplyKeyboardMarkup.java create mode 100644 src/main/java/org/telegram/api/objects/Sticker.java create mode 100644 src/main/java/org/telegram/api/objects/Update.java create mode 100644 src/main/java/org/telegram/api/objects/User.java create mode 100644 src/main/java/org/telegram/api/objects/UserProfilePhotos.java create mode 100644 src/main/java/org/telegram/api/objects/Video.java create mode 100644 src/main/java/org/telegram/api/objects/Voice.java create mode 100644 src/main/java/org/telegram/services/BotLogger.java create mode 100644 src/main/java/org/telegram/updateshandlers/SentCallback.java create mode 100644 src/main/java/org/telegram/updateshandlers/UpdatesCallback.java create mode 100644 src/main/java/org/telegram/updatesreceivers/RestApi.java create mode 100644 src/main/java/org/telegram/updatesreceivers/UpdatesThread.java create mode 100644 src/main/java/org/telegram/updatesreceivers/Webhook.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..23b437c2154a1e5ee4df5f7e507c1d9fc8ead69b GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8rh18}Ab8oU&_nAF#apa;6bh9VQK^XubfF}rNi9+eIr|v?KZYRs z4nB%EXLi@3R4*Px%1oI3W@l#-=3Cg!FvfVL=a(3>8DkbGVkQs6H-hV^W0El*4hU+q zxZ|}W4`y#(XDpf=|B(UQyDW=Ymz{b2&->SwaZ)V4@=P{2H9ceHXXo&-=Vwo9t*Bp1 z+@u#*-0qQ@Nk8z6U3HVzhkX!5?UC(zbs6-V_To+yCaw&F?x)n_h7A3vUx|95A0OBB z`x??uT1|VY+6~Sjwd#gJUB=RrZJAtHd3>7o@?fxDS}TZBd23h@gL1i85F6{|;n04x ztd-Tx?ft{f@bc>V=JxLX;ptiL0mrgY7Bq~;mytyVF+dCu0~5@EIRve_39gY!BL;|p z-!Xvag8)Tz45k{@(E)>M0RVI0RsuHm5||?lItEjXumZw$Dxgl~rp4eo9sI(?IR;aW zI-POTd~ow+ZaNgMz7FpfDx7ggBaOrWG4Pdvte)C<|L^_W|9?%Q88JW%OcVn=w_Dq- zKuP9q9V-s+S^;_rih^;e#!(6w>MDj + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 00000000..e7bedf33 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 00000000..49c237dd --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..38c7409a --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,49 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000..3b312839 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/jsLinters/jshint.xml b/.idea/jsLinters/jshint.xml new file mode 100644 index 00000000..11b997b6 --- /dev/null +++ b/.idea/jsLinters/jshint.xml @@ -0,0 +1,71 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_5_4.xml b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_5_4.xml new file mode 100644 index 00000000..086f4e91 --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_5_4.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_5_4.xml b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_5_4.xml new file mode 100644 index 00000000..40f4bc8c --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_5_4.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_5_4.xml b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_5_4.xml new file mode 100644 index 00000000..8adb4b6d --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_5_4.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_jaxrs_jackson_jaxrs_base_2_5_4.xml b/.idea/libraries/Maven__com_fasterxml_jackson_jaxrs_jackson_jaxrs_base_2_5_4.xml new file mode 100644 index 00000000..a64dd1ef --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_jaxrs_jackson_jaxrs_base_2_5_4.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_jaxrs_jackson_jaxrs_json_provider_2_5_4.xml b/.idea/libraries/Maven__com_fasterxml_jackson_jaxrs_jackson_jaxrs_json_provider_2_5_4.xml new file mode 100644 index 00000000..996db039 --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_jaxrs_jackson_jaxrs_json_provider_2_5_4.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_fasterxml_jackson_module_jackson_module_jaxb_annotations_2_5_4.xml b/.idea/libraries/Maven__com_fasterxml_jackson_module_jackson_module_jaxb_annotations_2_5_4.xml new file mode 100644 index 00000000..9f5e5cdc --- /dev/null +++ b/.idea/libraries/Maven__com_fasterxml_jackson_module_jackson_module_jaxb_annotations_2_5_4.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_sun_jersey_jersey_bundle_1_19.xml b/.idea/libraries/Maven__com_sun_jersey_jersey_bundle_1_19.xml new file mode 100644 index 00000000..015dbda0 --- /dev/null +++ b/.idea/libraries/Maven__com_sun_jersey_jersey_bundle_1_19.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_sun_jersey_jersey_core_1_19.xml b/.idea/libraries/Maven__com_sun_jersey_jersey_core_1_19.xml new file mode 100644 index 00000000..3ac29b22 --- /dev/null +++ b/.idea/libraries/Maven__com_sun_jersey_jersey_core_1_19.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_sun_jersey_jersey_grizzly2_1_19.xml b/.idea/libraries/Maven__com_sun_jersey_jersey_grizzly2_1_19.xml new file mode 100644 index 00000000..8734ae45 --- /dev/null +++ b/.idea/libraries/Maven__com_sun_jersey_jersey_grizzly2_1_19.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_sun_jersey_jersey_grizzly2_servlet_1_19.xml b/.idea/libraries/Maven__com_sun_jersey_jersey_grizzly2_servlet_1_19.xml new file mode 100644 index 00000000..2f3fb720 --- /dev/null +++ b/.idea/libraries/Maven__com_sun_jersey_jersey_grizzly2_servlet_1_19.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_sun_jersey_jersey_server_1_19.xml b/.idea/libraries/Maven__com_sun_jersey_jersey_server_1_19.xml new file mode 100644 index 00000000..47f74e7c --- /dev/null +++ b/.idea/libraries/Maven__com_sun_jersey_jersey_server_1_19.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_sun_jersey_jersey_servlet_1_19.xml b/.idea/libraries/Maven__com_sun_jersey_jersey_servlet_1_19.xml new file mode 100644 index 00000000..882f8424 --- /dev/null +++ b/.idea/libraries/Maven__com_sun_jersey_jersey_servlet_1_19.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_codec_commons_codec_1_9.xml b/.idea/libraries/Maven__commons_codec_commons_codec_1_9.xml new file mode 100644 index 00000000..a66d0394 --- /dev/null +++ b/.idea/libraries/Maven__commons_codec_commons_codec_1_9.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_logging_commons_logging_1_2.xml b/.idea/libraries/Maven__commons_logging_commons_logging_1_2.xml new file mode 100644 index 00000000..eab40b32 --- /dev/null +++ b/.idea/libraries/Maven__commons_logging_commons_logging_1_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_annotation_javax_annotation_api_1_2.xml b/.idea/libraries/Maven__javax_annotation_javax_annotation_api_1_2.xml new file mode 100644 index 00000000..e35b9369 --- /dev/null +++ b/.idea/libraries/Maven__javax_annotation_javax_annotation_api_1_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_servlet_javax_servlet_api_3_0_1.xml b/.idea/libraries/Maven__javax_servlet_javax_servlet_api_3_0_1.xml new file mode 100644 index 00000000..63d10f64 --- /dev/null +++ b/.idea/libraries/Maven__javax_servlet_javax_servlet_api_3_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_validation_validation_api_1_1_0_Final.xml b/.idea/libraries/Maven__javax_validation_validation_api_1_1_0_Final.xml new file mode 100644 index 00000000..940ce73c --- /dev/null +++ b/.idea/libraries/Maven__javax_validation_validation_api_1_1_0_Final.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_ws_rs_javax_ws_rs_api_2_0_1.xml b/.idea/libraries/Maven__javax_ws_rs_javax_ws_rs_api_2_0_1.xml new file mode 100644 index 00000000..c8901674 --- /dev/null +++ b/.idea/libraries/Maven__javax_ws_rs_javax_ws_rs_api_2_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_ws_rs_jsr311_api_1_1_1.xml b/.idea/libraries/Maven__javax_ws_rs_jsr311_api_1_1_1.xml new file mode 100644 index 00000000..a0c4d766 --- /dev/null +++ b/.idea/libraries/Maven__javax_ws_rs_jsr311_api_1_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_1.xml b/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_1.xml new file mode 100644 index 00000000..958a9faf --- /dev/null +++ b/.idea/libraries/Maven__org_apache_httpcomponents_httpclient_4_5_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_3.xml b/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_3.xml new file mode 100644 index 00000000..a9f8d494 --- /dev/null +++ b/.idea/libraries/Maven__org_apache_httpcomponents_httpcore_4_4_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_httpcomponents_httpmime_4_5_1.xml b/.idea/libraries/Maven__org_apache_httpcomponents_httpmime_4_5_1.xml new file mode 100644 index 00000000..793e63d6 --- /dev/null +++ b/.idea/libraries/Maven__org_apache_httpcomponents_httpmime_4_5_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_grizzly_grizzly_framework_2_3_22.xml b/.idea/libraries/Maven__org_glassfish_grizzly_grizzly_framework_2_3_22.xml new file mode 100644 index 00000000..a65bfbef --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_grizzly_grizzly_framework_2_3_22.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_grizzly_grizzly_http_2_3_22.xml b/.idea/libraries/Maven__org_glassfish_grizzly_grizzly_http_2_3_22.xml new file mode 100644 index 00000000..34ec7044 --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_grizzly_grizzly_http_2_3_22.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_grizzly_grizzly_http_server_2_3_22.xml b/.idea/libraries/Maven__org_glassfish_grizzly_grizzly_http_server_2_3_22.xml new file mode 100644 index 00000000..7a5c530c --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_grizzly_grizzly_http_server_2_3_22.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_grizzly_grizzly_http_servlet_2_2_16.xml b/.idea/libraries/Maven__org_glassfish_grizzly_grizzly_http_servlet_2_2_16.xml new file mode 100644 index 00000000..65fc7b28 --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_grizzly_grizzly_http_servlet_2_2_16.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_hk2_external_aopalliance_repackaged_2_4_0_b31.xml b/.idea/libraries/Maven__org_glassfish_hk2_external_aopalliance_repackaged_2_4_0_b31.xml new file mode 100644 index 00000000..874c8904 --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_hk2_external_aopalliance_repackaged_2_4_0_b31.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_hk2_external_javax_inject_2_4_0_b31.xml b/.idea/libraries/Maven__org_glassfish_hk2_external_javax_inject_2_4_0_b31.xml new file mode 100644 index 00000000..87ed3347 --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_hk2_external_javax_inject_2_4_0_b31.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_hk2_hk2_api_2_4_0_b31.xml b/.idea/libraries/Maven__org_glassfish_hk2_hk2_api_2_4_0_b31.xml new file mode 100644 index 00000000..14746f4c --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_hk2_hk2_api_2_4_0_b31.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_hk2_hk2_locator_2_4_0_b31.xml b/.idea/libraries/Maven__org_glassfish_hk2_hk2_locator_2_4_0_b31.xml new file mode 100644 index 00000000..e57e76f7 --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_hk2_hk2_locator_2_4_0_b31.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_hk2_hk2_utils_2_4_0_b31.xml b/.idea/libraries/Maven__org_glassfish_hk2_hk2_utils_2_4_0_b31.xml new file mode 100644 index 00000000..e99f9735 --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_hk2_hk2_utils_2_4_0_b31.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_hk2_osgi_resource_locator_1_0_1.xml b/.idea/libraries/Maven__org_glassfish_hk2_osgi_resource_locator_1_0_1.xml new file mode 100644 index 00000000..3d299fa6 --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_hk2_osgi_resource_locator_1_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_jersey_bundles_repackaged_jersey_guava_2_21.xml b/.idea/libraries/Maven__org_glassfish_jersey_bundles_repackaged_jersey_guava_2_21.xml new file mode 100644 index 00000000..36cb9dae --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_jersey_bundles_repackaged_jersey_guava_2_21.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_jersey_containers_jersey_container_grizzly2_http_2_21.xml b/.idea/libraries/Maven__org_glassfish_jersey_containers_jersey_container_grizzly2_http_2_21.xml new file mode 100644 index 00000000..56d71361 --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_jersey_containers_jersey_container_grizzly2_http_2_21.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_jersey_core_jersey_client_2_21.xml b/.idea/libraries/Maven__org_glassfish_jersey_core_jersey_client_2_21.xml new file mode 100644 index 00000000..e107b604 --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_jersey_core_jersey_client_2_21.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_jersey_core_jersey_common_2_21.xml b/.idea/libraries/Maven__org_glassfish_jersey_core_jersey_common_2_21.xml new file mode 100644 index 00000000..7c1bf6c6 --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_jersey_core_jersey_common_2_21.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_jersey_core_jersey_server_2_21.xml b/.idea/libraries/Maven__org_glassfish_jersey_core_jersey_server_2_21.xml new file mode 100644 index 00000000..5b375de5 --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_jersey_core_jersey_server_2_21.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_jersey_ext_jersey_entity_filtering_2_21.xml b/.idea/libraries/Maven__org_glassfish_jersey_ext_jersey_entity_filtering_2_21.xml new file mode 100644 index 00000000..70c17910 --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_jersey_ext_jersey_entity_filtering_2_21.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_jersey_media_jersey_media_jaxb_2_21.xml b/.idea/libraries/Maven__org_glassfish_jersey_media_jersey_media_jaxb_2_21.xml new file mode 100644 index 00000000..6af14c37 --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_jersey_media_jersey_media_jaxb_2_21.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_glassfish_jersey_media_jersey_media_json_jackson_2_21.xml b/.idea/libraries/Maven__org_glassfish_jersey_media_jersey_media_json_jackson_2_21.xml new file mode 100644 index 00000000..e063501a --- /dev/null +++ b/.idea/libraries/Maven__org_glassfish_jersey_media_jersey_media_json_jackson_2_21.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_javassist_javassist_3_18_1_GA.xml b/.idea/libraries/Maven__org_javassist_javassist_3_18_1_GA.xml new file mode 100644 index 00000000..1f907308 --- /dev/null +++ b/.idea/libraries/Maven__org_javassist_javassist_3_18_1_GA.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_json_json_20141113.xml b/.idea/libraries/Maven__org_json_json_20141113.xml new file mode 100644 index 00000000..2f486e75 --- /dev/null +++ b/.idea/libraries/Maven__org_json_json_20141113.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..3bb9901e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /usr/local/bin/bower + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..d845503c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/resourceBundles.xml b/.idea/resourceBundles.xml new file mode 100644 index 00000000..7267597b --- /dev/null +++ b/.idea/resourceBundles.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 00000000..e96534fb --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/BotAPi.iml b/BotAPi.iml new file mode 100644 index 00000000..efee40fe --- /dev/null +++ b/BotAPi.iml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..733c0723 --- /dev/null +++ b/LICENSE @@ -0,0 +1,675 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. + diff --git a/README.md b/README.md new file mode 100644 index 00000000..7c4f97f9 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Telegram Bot Java Library +A simple to use library to create Telegram Bots in Java (Still Beta Version) + +## Translations +Bots are now supporting multilanguage. If you want to add your own, feel free to translate at [transifex](https://www.transifex.com/projects/p/telegrambots/) + +## Contributions +Feel free to fork this project, work on it and then make a pull request. Most of the times I will accept them if they add something valuable to the code. + +Please, **DO NOT PUSH ANY TOKEN OR API KEY**, I will never accept a pull request with that content. + +## Webhooks vs GetUpdates +Both ways are supported (but I still didn't tested webhooks). To change between them, just go to *BuildVars.java* and change variable *useWebHook* value. + +I recommend using getUpdates methods. Webhooks only works using a certificated that is not self-signed + +## Example bots +Open them and send them */help* command to get some information about their capabilities: + +https://telegram.me/weatherbot + +https://telegram.me/directionsbot + +https://telegram.me/filesbot + +https://telegram.me/TGlanguagesbot + +## Telegram Bot API +This library use [Telegram bot API](https://core.telegram.org/bots), you can find more information following the link. + +## Questions or Suggestions +Feel free to create issues [here](https://github.com/rubenlagus/TelegramBots/issues) as you need + +## Usage with eclipse + +Follow the steps created by Rico [here](https://github.com/rubenlagus/TelegramBots/blob/master/eclipse%20configuration.md) + +## License + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . diff --git a/eclipse configuration.md b/eclipse configuration.md new file mode 100644 index 00000000..8637ab1a --- /dev/null +++ b/eclipse configuration.md @@ -0,0 +1,27 @@ +# How to use TelegramBots with Eclipse + + +### Step 1: Install Maven +To get started, you need to install the Maven-Plugin for Eclipse. Click on Help > Eclipse Marketplace. After it finished loading, search for “Maven”. +Now install **“Maven (Java EE) Integration for Eclipse WTP”**. You have to restart, after the installation is completed. + +### Step 2: Download the Project +Now you need to get the project itself. +Visit [TelegramBots - github.com][1] and choose “Download Zip”, to download the zip-file. [Here] is a direct link if you are lazy. + +### Step 3: Create folder +Now let’s setup the project-folder. Go to your Eclipse-Workspace and create a folder (name it whatever you want it to be called). I just named it **“TelegramBotApi”**. Afterwards copy everything from the zip-file into that folder. + +### Step 4: Import project +To import your project into the workspace you have to go to File > Import > (Folder) Maven > Existing Maven Projects > Next. Choose the folder, you have created in Step 3. In my case: **“TelegramBotApi”**. Click on finish and let Maven import the dependencies. + +### Step 5: Setting the compliance level +In this last step you need to change the Compiler compliance level. To do this right-click on your Project (in my case **“TelegramBotApi”**) > Properties > Java Compiler. Uncheck the “Use compliance from…” if necessary and set it to 1.7 + +*Now you are done. Everything should work fine. You need to set your Bot-Token in the BotConfig.java, afterwards you can run Main.java to check.* + +**For a better intstruction sheet, visit [Google Drive]** + +[Google Drive]:https://goo.gl/5jd40w +[here]:https://github.com/rubenlagus/TelegramBots/archive/master.zip +[1]:https://github.com/rubenlagus/TelegramBots/ diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..09ab5ced --- /dev/null +++ b/pom.xml @@ -0,0 +1,146 @@ + + + 4.0.0 + + TelegramBots + org.telegram.telegrambots + 1.0 + + + UTF-8 + UTF-8 + 2.21 + 4.5.1 + + + + + + org.glassfish.jersey + jersey-bom + ${jersey.version} + pom + import + + + + + + + org.glassfish.jersey.containers + jersey-container-grizzly2-http + + + org.glassfish.jersey.media + jersey-media-json-jackson + ${jersey.version} + + + com.sun.jersey + jersey-bundle + 1.19 + + + com.sun.jersey + jersey-grizzly2-servlet + 1.19 + + + org.json + json + 20141113 + + + org.apache.httpcomponents + httpclient + ${httpcompontents.version} + + + org.apache.httpcomponents + httpmime + ${httpcompontents.version} + + + + + ${project.basedir}/target + ${project.build.directory}/classes + ${project.artifactId}-${project.version} + ${project.build.directory}/test-classes + ${project.basedir}/src/main/java + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + true + lib/ + org.telegram.Main + + + + + + maven-assembly-plugin + + + + org.telegram.Main + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.9 + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/lib + false + false + true + + + + + + maven-clean-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + UTF-8 + + + + + + \ No newline at end of file diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..21ed6df661fd723c103f3518a187bd98a2637faf GIT binary patch literal 6148 zcmeHK%}T>S5Zz5d_8DkbGVkQT}H-hV^W0El*4hU*9 zuNSwyR^-9_eJq+B|B(UQyDU3rE|V<$x_@4~CF7)6eB+s^?DWj6mCMiJW6$SL>&>WF zPu!#%SKQ9Ann^$Kj9qh+=BK?MMXjOjdIvJ-HSEQmC`?=#2AwadCx!r1VD3!Mc1<@~;iv_WYFM8{yNQ5_vHs1^V)3vMM~V=sX@!k}X?)d(vfT&Du+RBl=fuG7IUOq^pd z)u_`MH_Zn(U*@Jm;p*$~exbq{cQn#S3=jjO3{2^%jrafV&;9>s63vJKVql^e;Mr=u zT7il2s8fYK}{*-|a D?o?k2 literal 0 HcmV?d00001 diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9d2a42b384b31f1b70c5b2a6473c440e430d708c GIT binary patch literal 6148 zcmeHK%}T>S5ZAzTq%BekIr|v?KZYRs z4nB%EXLi@3R4*Px%1oI3W@l#-=3Cg!FvfVf>lYcb8DkbGVkQT}H-hV^W0El*4hU*9 zuOGL)R^-9_Z7iA`|B(UQyDU3rF6%M(^Zt45mW-1^;gx5mvePrOR&H({AA4c$wAzgN z)x=G@aoO#hsG0Nw&)5|=X@1y;QPdjQu6HDZe#2hcjl#s0VbJ-MTCd5_kNV}P8~Sm* zs^3?We$s5%%au;hgVc%}21hcMo@~kF!ph;(uvZ3yjpBM<6ieH~ycm>9g}m6@C=G}9 zqh+nGZS5Q!w}+Qk*EhF!_YY6cdKWkrjG`@^1GKc|UfEbuq2Fwv?%};EFR2VTp z4E&Y>JRbxoqGK@CsE!U8R0{x@1-BBgv6sLcVbC#{YJ?RKu2TVZDmN_#*XiIFCeAUK zYSihBo92U?FLTqOaP@U~zfj?fI~r*u28e;L3{2^%jrafl&;9?`B$^Qe#K1%`z_WYR zy)u+!?$)v5@U9i0XP_t;mueiPfT6Bph{daT1yl+61sZ^k!Biu7KS5Z-O8rh18}Ab8oU&_nAF#apa;6bh9VQK<8DkbGVkQs6H-hV^W0El*4hU+q zxZ|}W4`y#(XDpf=|B(UQyDW=Xmz{b2&->SwaZ)V4@=P{2H9ceHXXo&-=Vwo9t*Bp1 z+@u#*-0qQ@Nk8z6U3HVzhkX!5?UC(zbs6-V_To+yCaw&F?x)n_h7A3vUx|95A0OBB z`x??uT1|VY+6~Sjwd#gJUB=RrZJAtHd3>7o@?fxDS}TZBd23h@gL1i85F6{|;n04x ztd-Tx?ft{f@bc>V=JxLX;ptiL0mrgY7Bq~;mytyVF+dCu0~5@EIRve_39gY!BL;|p z-!Xvag8)Tz45k{@(E)>M0RVI0RsuHm5||?lItEjXumZw$Dxgl~rp4eo9sI(?IR;aW zI-POTd~ow+ZaNgMz7FpfDx7ggBaOrWG4Pdvte)C<|L^_W|9?%Q88JW%OcVn=w_Dq- zKuP9q9V-s+S^;_rih^;e#!(6w>MDj nameValuePairs = new ArrayList<>(); + nameValuePairs.add(new BasicNameValuePair(SendDocument.CHATID_FIELD, sendDocument.getChatId())); + nameValuePairs.add(new BasicNameValuePair(SendDocument.DOCUMENT_FIELD, sendDocument.getDocument())); + if (sendDocument.getReplayMarkup() != null) { + nameValuePairs.add(new BasicNameValuePair(SendDocument.REPLYMARKUP_FIELD, sendDocument.getReplayMarkup().toString())); + } + if (sendDocument.getReplayToMessageId() != null) { + nameValuePairs.add(new BasicNameValuePair(SendDocument.REPLYTOMESSAGEID_FIELD, sendDocument.getReplayToMessageId().toString())); + } + httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); + } + + CloseableHttpResponse response = httpClient.execute(httppost); + } catch (IOException e) { + BotLogger.error(LOGTAG, e); + } finally { + if (sendDocument.isNewDocument()) { + File fileToDelete = new File(sendDocument.getDocument()); + fileToDelete.delete(); + } + } + } + + public static void SendPhoto(SendPhoto sendPhoto, String botToken) { + try { + CloseableHttpClient httpClient = HttpClients.createDefault(); + String url = Constants.BASEURL + botToken + "/" + SendPhoto.PATH; + HttpPost httppost = new HttpPost(url); + + if (sendPhoto.isNewPhoto()) { + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + builder.addTextBody(SendPhoto.CHATID_FIELD, sendPhoto.getChatId()); + builder.addBinaryBody(SendPhoto.PHOTO_FIELD, new File(sendPhoto.getPhoto()), ContentType.APPLICATION_OCTET_STREAM, sendPhoto.getPhotoName()); + if (sendPhoto.getReplayMarkup() != null) { + builder.addTextBody(SendPhoto.REPLYMARKUP_FIELD, sendPhoto.getReplayMarkup().toJson().toString()); + } + if (sendPhoto.getReplayToMessageId() != null) { + builder.addTextBody(SendPhoto.REPLYTOMESSAGEID_FIELD, sendPhoto.getReplayToMessageId().toString()); + } + if (sendPhoto.getCaption() != null) { + builder.addTextBody(SendPhoto.CAPTION_FIELD, sendPhoto.getCaption()); + } + HttpEntity multipart = builder.build(); + httppost.setEntity(multipart); + } else { + List nameValuePairs = new ArrayList<>(); + nameValuePairs.add(new BasicNameValuePair(SendPhoto.CHATID_FIELD, sendPhoto.getChatId())); + nameValuePairs.add(new BasicNameValuePair(SendPhoto.PHOTO_FIELD, sendPhoto.getPhoto())); + if (sendPhoto.getReplayMarkup() != null) { + nameValuePairs.add(new BasicNameValuePair(SendPhoto.REPLYMARKUP_FIELD, sendPhoto.getReplayMarkup().toString())); + } + if (sendPhoto.getReplayToMessageId() != null) { + nameValuePairs.add(new BasicNameValuePair(SendPhoto.REPLYTOMESSAGEID_FIELD, sendPhoto.getReplayToMessageId().toString())); + } + if (sendPhoto.getCaption() != null) { + nameValuePairs.add(new BasicNameValuePair(SendPhoto.CAPTION_FIELD, sendPhoto.getCaption())); + } + httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); + } + + CloseableHttpResponse response = httpClient.execute(httppost); + } catch (IOException e) { + BotLogger.error(LOGTAG, e); + } + } + + public static void SendVideo(SendVideo sendVideo, String botToken) { + try { + CloseableHttpClient httpClient = HttpClients.createDefault(); + String url = Constants.BASEURL + botToken + "/" + SendVideo.PATH; + HttpPost httppost = new HttpPost(url); + + if (sendVideo.isNewVideo()) { + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + builder.addTextBody(SendVideo.CHATID_FIELD, sendVideo.getChatId()); + builder.addBinaryBody(SendVideo.VIDEO_FIELD, new File(sendVideo.getVideo()), ContentType.APPLICATION_OCTET_STREAM, sendVideo.getVideoName()); + if (sendVideo.getReplayMarkup() != null) { + builder.addTextBody(SendVideo.REPLYMARKUP_FIELD, sendVideo.getReplayMarkup().toJson().toString()); + } + if (sendVideo.getReplayToMessageId() != null) { + builder.addTextBody(SendVideo.REPLYTOMESSAGEID_FIELD, sendVideo.getReplayToMessageId().toString()); + } + if (sendVideo.getCaption() != null) { + builder.addTextBody(SendVideo.CAPTION_FIELD, sendVideo.getCaption()); + } + if (sendVideo.getDuration() != null) { + builder.addTextBody(SendVideo.DURATION_FIELD, sendVideo.getDuration().toString()); + } + HttpEntity multipart = builder.build(); + httppost.setEntity(multipart); + } else { + List nameValuePairs = new ArrayList<>(); + nameValuePairs.add(new BasicNameValuePair(SendVideo.CHATID_FIELD, sendVideo.getChatId())); + nameValuePairs.add(new BasicNameValuePair(SendVideo.VIDEO_FIELD, sendVideo.getVideo())); + if (sendVideo.getReplayMarkup() != null) { + nameValuePairs.add(new BasicNameValuePair(SendVideo.REPLYMARKUP_FIELD, sendVideo.getReplayMarkup().toString())); + } + if (sendVideo.getReplayToMessageId() != null) { + nameValuePairs.add(new BasicNameValuePair(SendVideo.REPLYTOMESSAGEID_FIELD, sendVideo.getReplayToMessageId().toString())); + } + if (sendVideo.getCaption() != null) { + nameValuePairs.add(new BasicNameValuePair(SendVideo.CAPTION_FIELD, sendVideo.getCaption())); + } + if (sendVideo.getDuration() != null) { + nameValuePairs.add(new BasicNameValuePair(SendVideo.DURATION_FIELD, sendVideo.getDuration().toString())); + } + httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); + } + + CloseableHttpResponse response = httpClient.execute(httppost); + } catch (IOException e) { + BotLogger.error(LOGTAG, e); + } + } + + public static void sendSticker(SendSticker sendSticker, String botToken) { + try { + CloseableHttpClient httpClient = HttpClients.createDefault(); + String url = Constants.BASEURL + botToken + "/" + SendSticker.PATH; + HttpPost httppost = new HttpPost(url); + + if (sendSticker.isNewSticker()) { + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + builder.addTextBody(SendSticker.CHATID_FIELD, sendSticker.getChatId()); + builder.addBinaryBody(SendSticker.STICKER_FIELD, new File(sendSticker.getSticker()), ContentType.APPLICATION_OCTET_STREAM, sendSticker.getStickerName()); + if (sendSticker.getReplayMarkup() != null) { + builder.addTextBody(SendSticker.REPLYMARKUP_FIELD, sendSticker.getReplayMarkup().toJson().toString()); + } + if (sendSticker.getReplayToMessageId() != null) { + builder.addTextBody(SendSticker.REPLYTOMESSAGEID_FIELD, sendSticker.getReplayToMessageId().toString()); + } + HttpEntity multipart = builder.build(); + httppost.setEntity(multipart); + } else { + List nameValuePairs = new ArrayList<>(); + nameValuePairs.add(new BasicNameValuePair(SendSticker.CHATID_FIELD, sendSticker.getChatId())); + nameValuePairs.add(new BasicNameValuePair(SendSticker.STICKER_FIELD, sendSticker.getSticker())); + if (sendSticker.getReplayMarkup() != null) { + nameValuePairs.add(new BasicNameValuePair(SendSticker.REPLYMARKUP_FIELD, sendSticker.getReplayMarkup().toString())); + } + if (sendSticker.getReplayToMessageId() != null) { + nameValuePairs.add(new BasicNameValuePair(SendSticker.REPLYTOMESSAGEID_FIELD, sendSticker.getReplayToMessageId().toString())); + } + httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); + } + + CloseableHttpResponse response = httpClient.execute(httppost); + } catch (IOException e) { + BotLogger.error(LOGTAG, e); + } finally { + if (sendSticker.isNewSticker()) { + File fileToDelete = new File(sendSticker.getSticker()); + fileToDelete.delete(); + } + } + } + + public static void SendWebhook(String webHookURL, String botToken, String publicCertificatePath, String publicCertificateName) { + try { + CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); + String url = Constants.BASEURL + botToken + "/" + SetWebhook.PATH; + + HttpPost httppost = new HttpPost(url); + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + builder.addTextBody(SetWebhook.URL_FIELD, webHookURL); + if (publicCertificatePath != null) { + builder.addBinaryBody(SetWebhook.CERTIFICATE_FIELD, new File(publicCertificatePath), ContentType.APPLICATION_OCTET_STREAM, publicCertificateName); + } + HttpEntity multipart = builder.build(); + httppost.setEntity(multipart); + CloseableHttpResponse response = httpclient.execute(httppost); + HttpEntity ht = response.getEntity(); + BufferedHttpEntity buf = new BufferedHttpEntity(ht); + String responseContent = EntityUtils.toString(buf, "UTF-8"); + BotLogger.debug(LOGTAG, responseContent); + } catch (IOException e) { + BotLogger.error(LOGTAG, e); + } + + } + + public static void SendApiMethod(BotApiMethod method, String botToken) throws InvalidObjectException { + String responseContent = "{}"; + try { + CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); + String url = Constants.BASEURL + botToken + "/" + method.getPath(); + HttpPost httppost = new HttpPost(url); + httppost.addHeader("charset", "UTF-8"); + httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON)); + CloseableHttpResponse response = httpclient.execute(httppost); + HttpEntity ht = response.getEntity(); + BufferedHttpEntity buf = new BufferedHttpEntity(ht); + responseContent = EntityUtils.toString(buf, "UTF-8"); + } catch (IOException e) { + BotLogger.error(LOGTAG, e); + } + + JSONObject jsonObject = new JSONObject(responseContent); + if (!jsonObject.getBoolean("ok")) { + throw new InvalidObjectException(jsonObject.getString("description")); + } + + } + + public static void SendApiMethodAsync(BotApiMethod method, String botToken, SentCallback callback) { + exe.submit(() -> { + try { + CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); + String url = Constants.BASEURL + botToken + "/" + method.getPath(); + HttpPost httppost = new HttpPost(url); + httppost.addHeader("charset", "UTF-8"); + httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON)); + CloseableHttpResponse response = httpclient.execute(httppost); + HttpEntity ht = response.getEntity(); + BufferedHttpEntity buf = new BufferedHttpEntity(ht); + String responseContent = EntityUtils.toString(buf, "UTF-8"); + + JSONObject jsonObject = new JSONObject(responseContent); + if (!jsonObject.getBoolean("ok")) { + callback.onError(method, jsonObject); + } + callback.onResult(method, jsonObject); + } catch (IOException e) { + BotLogger.error(LOGTAG, e); + } + }); + } +} diff --git a/src/main/java/org/telegram/api/interfaces/BotApiObject.java b/src/main/java/org/telegram/api/interfaces/BotApiObject.java new file mode 100644 index 00000000..fac118d8 --- /dev/null +++ b/src/main/java/org/telegram/api/interfaces/BotApiObject.java @@ -0,0 +1,13 @@ +package org.telegram.api.interfaces; + +import com.fasterxml.jackson.databind.JsonSerializable; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief An object of Telegram Bots Api + * @date 07 of September of 2015 + */ +public interface BotApiObject extends JsonSerializable { +} diff --git a/src/main/java/org/telegram/api/interfaces/IToJson.java b/src/main/java/org/telegram/api/interfaces/IToJson.java new file mode 100644 index 00000000..921bfbe1 --- /dev/null +++ b/src/main/java/org/telegram/api/interfaces/IToJson.java @@ -0,0 +1,18 @@ +package org.telegram.api.interfaces; + +import org.json.JSONObject; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Add conversion to JSON object + * @date 08 of September of 2015 + */ +public interface IToJson { + + /** + * Convert to json object + * @return JSONObject created in the conversion + */ + JSONObject toJson(); +} diff --git a/src/main/java/org/telegram/api/methods/AnswerInlineQuery.java b/src/main/java/org/telegram/api/methods/AnswerInlineQuery.java new file mode 100644 index 00000000..21071fbd --- /dev/null +++ b/src/main/java/org/telegram/api/methods/AnswerInlineQuery.java @@ -0,0 +1,138 @@ +package org.telegram.api.methods; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONArray; +import org.json.JSONObject; +import org.telegram.api.objects.InlineQueryResult; + +import java.io.IOException; +import java.util.List; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to send answers to an inline query. On success, True is returned. + * @date 01 of January of 2016 + */ +public class AnswerInlineQuery extends BotApiMethod { + public static final String PATH = "answerInlineQuery"; + + public static final String INLINEQUERYID_FIELD = "inline_query_id"; + private String inlineQueryId; ///< Unique identifier for answered query + public static final String RESULTS_FIELD = "results"; + private List results; ///< A JSON-serialized array of results for the inline query + public static final String CACHETIME_FIELD = "cache_time"; + private Integer cacheTime; ///< Optional The maximum amount of time the result of the inline query may be cached on the server + public static final String ISPERSONAL_FIELD = "is_personal"; + private Boolean isPersonal; ///< Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query + public static final String NEXTOFFSET_FIELD = "next_offset"; + private String nextOffset; ///< Optional Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes. + + public AnswerInlineQuery() { + super(); + } + + public String getInlineQueryId() { + return inlineQueryId; + } + + public void setInlineQueryId(String inlineQueryId) { + this.inlineQueryId = inlineQueryId; + } + + public List getResults() { + return results; + } + + public void setResults(List results) { + this.results = results; + } + + public Integer getCacheTime() { + return cacheTime; + } + + public void setCacheTime(Integer cacheTime) { + this.cacheTime = cacheTime; + } + + public Boolean getPersonal() { + return isPersonal; + } + + public void setPersonal(Boolean personal) { + isPersonal = personal; + } + + public String getNextOffset() { + return nextOffset; + } + + public void setNextOffset(String nextOffset) { + this.nextOffset = nextOffset; + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(INLINEQUERYID_FIELD, inlineQueryId); + JSONArray JSONResults = new JSONArray(); + for (InlineQueryResult result: results) { + JSONResults.put(result.toJson()); + } + jsonObject.put(RESULTS_FIELD, JSONResults); + if (cacheTime != null) { + jsonObject.put(CACHETIME_FIELD, cacheTime); + } + if (isPersonal != null) { + jsonObject.put(ISPERSONAL_FIELD, isPersonal); + } + if (nextOffset != null) { + jsonObject.put(NEXTOFFSET_FIELD, nextOffset); + } + return jsonObject; + } + + @Override + public String getPath() { + return PATH; + } + + @Override + public Boolean deserializeResponse(JSONObject answer) { + if (answer.getBoolean("ok")) { + return answer.getBoolean("result"); + } + return null; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(METHOD_FIELD, PATH); + gen.writeArrayFieldStart(RESULTS_FIELD); + for (InlineQueryResult result: results) { + gen.writeObject(result); + } + gen.writeEndArray(); + if (cacheTime != null) { + gen.writeNumberField(CACHETIME_FIELD, cacheTime); + } + if (isPersonal != null) { + gen.writeBooleanField(ISPERSONAL_FIELD, isPersonal); + } + if (nextOffset != null) { + gen.writeStringField(NEXTOFFSET_FIELD, nextOffset); + } + + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/methods/BotApiMethod.java b/src/main/java/org/telegram/api/methods/BotApiMethod.java new file mode 100644 index 00000000..c6a25820 --- /dev/null +++ b/src/main/java/org/telegram/api/methods/BotApiMethod.java @@ -0,0 +1,28 @@ +package org.telegram.api.methods; + +import com.fasterxml.jackson.databind.JsonSerializable; +import org.json.JSONObject; +import org.telegram.api.interfaces.IToJson; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief A method of Telegram Bots Api that is fully supported in json format + * @date 07 of September of 2015 + */ +public abstract class BotApiMethod implements JsonSerializable, IToJson { + protected static final String METHOD_FIELD = "method"; + + /** + * Getter for method path (that is the same as method name) + * @return Method path + */ + public abstract String getPath(); + + /** + * Deserialize a json answer to the response type to a method + * @param answer Json answer received + * @return Answer for the method + */ + public abstract T deserializeResponse(JSONObject answer); +} diff --git a/src/main/java/org/telegram/api/methods/Constants.java b/src/main/java/org/telegram/api/methods/Constants.java new file mode 100644 index 00000000..8464418e --- /dev/null +++ b/src/main/java/org/telegram/api/methods/Constants.java @@ -0,0 +1,11 @@ +package org.telegram.api.methods; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief TODO + * @date 20 of June of 2015 + */ +public class Constants { + public static final String BASEURL = "https://api.telegram.org/bot"; +} diff --git a/src/main/java/org/telegram/api/methods/ForwardMessage.java b/src/main/java/org/telegram/api/methods/ForwardMessage.java new file mode 100644 index 00000000..11a41f1f --- /dev/null +++ b/src/main/java/org/telegram/api/methods/ForwardMessage.java @@ -0,0 +1,92 @@ +package org.telegram.api.methods; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.objects.Message; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to send text messages. On success, the sent Message is returned. + * @date 20 of June of 2015 + */ +public class ForwardMessage extends BotApiMethod { + public static final String PATH = "forwardmessage"; + + public static final String CHATID_FIELD = "chat_id"; + private String chatId; ///< Unique identifier for the chat to send the message to (or username for channels) + public static final String FROMCHATID_FIELD = "from_chat_id"; + private Integer fromChatId; ///< Unique identifier for the chat where the original message was sent — User or GroupChat id + public static final String MESSAGEID_FIELD = "message_id"; + private Integer messageId; ///< Unique message identifier + + public ForwardMessage() { + super(); + } + + public String getChatId() { + return chatId; + } + + public void setChatId(String chatId) { + this.chatId = chatId; + } + + public Integer getFromChatId() { + return fromChatId; + } + + public void setFromChatId(Integer fromChatId) { + this.fromChatId = fromChatId; + } + + public Integer getMessageId() { + return messageId; + } + + public void setMessageId(Integer messageId) { + this.messageId = messageId; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(METHOD_FIELD, PATH); + gen.writeStringField(CHATID_FIELD, chatId); + gen.writeNumberField(FROMCHATID_FIELD, fromChatId); + gen.writeNumberField(MESSAGEID_FIELD, messageId); + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(CHATID_FIELD, chatId); + jsonObject.put(FROMCHATID_FIELD, fromChatId); + jsonObject.put(MESSAGEID_FIELD, messageId); + return jsonObject; + } + + @Override + public String getPath() { + return PATH; + } + + @Override + public Message deserializeResponse(JSONObject answer) { + if (answer.getBoolean("ok")) { + return new Message(answer.getJSONObject("result")); + } + return null; + } +} diff --git a/src/main/java/org/telegram/api/methods/GetFile.java b/src/main/java/org/telegram/api/methods/GetFile.java new file mode 100644 index 00000000..2f49040d --- /dev/null +++ b/src/main/java/org/telegram/api/methods/GetFile.java @@ -0,0 +1,74 @@ +package org.telegram.api.methods; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.objects.File; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to get basic info about a file and prepare it for downloading. + * For the moment, bots can download files of up to 20MB in size. + * On success, a File object is returned. + * The file can then be downloaded via the link https://api.telegram.org/file/bot/, + * where is taken from the response. + * It is guaranteed that the link will be valid for at least 1 hour. + * When the link expires, a new one can be requested by calling getFile again. + * @date 20 of June of 2015 + */ +public class GetFile extends BotApiMethod { + public static final String PATH = "getfield"; + + public static final String FILEID_FIELD = "file_id"; + private String fileId; ///< File identifier to get info about + + public GetFile() { + super(); + } + + public String getFileId() { + return fileId; + } + + public void setFileId(String fileId) { + this.fileId = fileId; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(METHOD_FIELD, PATH); + gen.writeStringField(FILEID_FIELD, fileId); + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(FILEID_FIELD, fileId); + return jsonObject; + } + + @Override + public String getPath() { + return PATH; + } + + @Override + public File deserializeResponse(JSONObject answer) { + if (answer.getBoolean("ok")) { + return new File(answer.getJSONObject("result")); + } + return null; + } +} diff --git a/src/main/java/org/telegram/api/methods/GetMe.java b/src/main/java/org/telegram/api/methods/GetMe.java new file mode 100644 index 00000000..601686e8 --- /dev/null +++ b/src/main/java/org/telegram/api/methods/GetMe.java @@ -0,0 +1,50 @@ +package org.telegram.api.methods; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.objects.User; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief A simple method for testing your bot's auth token. Requires no parameters. + * Returns basic information about the bot in form of a User object + * @date 20 of June of 2015 + */ +public class GetMe extends BotApiMethod { + public static final String PATH = "getme"; + + @Override + public JSONObject toJson() { + return new JSONObject(); + } + + @Override + public String getPath() { + return PATH; + } + + @Override + public User deserializeResponse(JSONObject answer) { + if (answer.getBoolean("ok")) { + return new User(answer.getJSONObject("result")); + } + return null; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(METHOD_FIELD, PATH); + gen.writeEndObject(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/methods/GetUpdates.java b/src/main/java/org/telegram/api/methods/GetUpdates.java new file mode 100644 index 00000000..f4ed66c9 --- /dev/null +++ b/src/main/java/org/telegram/api/methods/GetUpdates.java @@ -0,0 +1,77 @@ +package org.telegram.api.methods; + +import org.json.JSONObject; +import org.telegram.api.interfaces.IToJson; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to receive incoming updates using long polling (wiki). + * An Array of Update objects is returned. + * @date 20 of June of 2015 + */ +public class GetUpdates implements IToJson { + public static final String PATH = "getupdates"; + + public static final String OFFSET_FIELD = "offset"; + /** + * Optional Identifier of the first update to be returned. + * Must be greater by one than the highest among the identifiers of previously received updates. + * By default, updates starting with the earliest unconfirmed update are returned. + */ + private Integer offset; + public static final String LIMIT_FIELD = "limit"; + /** + * Optional Limits the number of updates to be retrieved. + * Values between 1—100 are accepted. Defaults to 100 + */ + private Integer limit; + public static final String TIMEOUT_FIELD = "timeout"; + /** + * Optional Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling + */ + private Integer timeout; + + public GetUpdates() { + super(); + } + + public Integer getOffset() { + return offset; + } + + public void setOffset(Integer offset) { + this.offset = offset; + } + + public Integer getLimit() { + return limit; + } + + public void setLimit(Integer limit) { + this.limit = limit; + } + + public Integer getTimeout() { + return timeout; + } + + public void setTimeout(Integer timeout) { + this.timeout = timeout; + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + if (offset != null) { + jsonObject.put(OFFSET_FIELD, offset); + } + if (limit != null) { + jsonObject.put(LIMIT_FIELD, limit); + } + if (timeout != null) { + jsonObject.put(TIMEOUT_FIELD, timeout); + } + return jsonObject; + } +} diff --git a/src/main/java/org/telegram/api/methods/GetUserProfilePhotos.java b/src/main/java/org/telegram/api/methods/GetUserProfilePhotos.java new file mode 100644 index 00000000..90c032b3 --- /dev/null +++ b/src/main/java/org/telegram/api/methods/GetUserProfilePhotos.java @@ -0,0 +1,102 @@ +package org.telegram.api.methods; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.objects.UserProfilePhotos; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object. + * @date 20 of June of 2015 + */ +public class GetUserProfilePhotos extends BotApiMethod { + public static final String PATH = "getuserprofilephotos"; + + public static final String USERID_FIELD = "user_id"; + private Integer userId; ///< Unique identifier of the target user + public static final String OFFSET_FIELD = "offset"; + /** + * Sequential number of the first photo to be returned. By default, all photos are returned. + */ + private Integer offset; + public static final String LIMIT_FIELD = "limit"; + /** + * Optional. Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100. + */ + private Integer limit; + + public GetUserProfilePhotos() { + super(); + } + + + public Integer getUserId() { + return userId; + } + + public void setUserId(Integer userId) { + this.userId = userId; + } + + public Integer getOffset() { + return offset; + } + + public void setOffset(Integer offset) { + this.offset = offset; + } + + public Integer getLimit() { + return limit; + } + + public void setLimit(Integer limit) { + this.limit = limit; + } + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(USERID_FIELD, userId); + jsonObject.put(OFFSET_FIELD, offset); + if (limit != null) { + jsonObject.put(LIMIT_FIELD, limit); + } + return jsonObject; + } + + @Override + public String getPath() { + return PATH; + } + + @Override + public UserProfilePhotos deserializeResponse(JSONObject answer) { + if (answer.getBoolean("ok")) { + return new UserProfilePhotos(answer.getJSONObject("result")); + } + return null; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(METHOD_FIELD, PATH); + gen.writeNumberField(USERID_FIELD, userId); + gen.writeNumberField(OFFSET_FIELD, offset); + if (limit != null) { + gen.writeNumberField(LIMIT_FIELD, limit); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/methods/SendAudio.java b/src/main/java/org/telegram/api/methods/SendAudio.java new file mode 100644 index 00000000..045dbf92 --- /dev/null +++ b/src/main/java/org/telegram/api/methods/SendAudio.java @@ -0,0 +1,104 @@ +package org.telegram.api.methods; + +import org.telegram.api.objects.ReplyKeyboard; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to send audio files, + * Use this method to send audio files, if you want Telegram clients to display them in the music player. + * Your audio must be in an .mp3 format. On success, the sent Message is returned. + * Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. + * + * @note For backward compatibility, when both fields title and description are empty and mime-type of the sent + * file is not “audio/mpeg”, file is sent as playable voice message. + * In this case, your audio must be in an .ogg file encoded with OPUS. + * This will be removed in the future. You need to use sendVoice method instead. + * + * @date 16 of July of 2015 + */ +public class SendAudio { + public static final String PATH = "sendaudio"; + + public static final String CHATID_FIELD = "chat_id"; + private String chatId; ///< Unique identifier for the chat to send the message to (or Username fro channels) + public static final String AUDIO_FIELD = "audio"; + private String audio; ///< Audio file to send. file_id as String to resend an audio that is already on the Telegram servers + public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id"; + private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message + public static final String REPLYMARKUP_FIELD = "reply_markup"; + private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard + public static final String PERFOMER_FIELD = "performer"; + private String performer; ///< Optional. Performer of sent audio + public static final String TITLE_FIELD = "title"; + private String title; ///< Optional. Title of sent audio + private boolean isNewAudio; + private String audioName; + + public SendAudio() { + super(); + } + + public String getChatId() { + return chatId; + } + + public void setChatId(String chatId) { + this.chatId = chatId; + } + + public String getAudio() { + return audio; + } + + public void setAudio(String audio) { + this.audio = audio; + this.isNewAudio = false; + } + + public void setNewAudio(String audio, String audioName) { + this.audio = audio; + this.isNewAudio = true; + this.audioName = audioName; + } + + public Integer getReplayToMessageId() { + return replayToMessageId; + } + + public void setReplayToMessageId(Integer replayToMessageId) { + this.replayToMessageId = replayToMessageId; + } + + public ReplyKeyboard getReplayMarkup() { + return replayMarkup; + } + + public void setReplayMarkup(ReplyKeyboard replayMarkup) { + this.replayMarkup = replayMarkup; + } + + public String getPerformer() { + return performer; + } + + public void setPerformer(String performer) { + this.performer = performer; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public boolean isNewAudio() { + return isNewAudio; + } + + public String getAudioName() { + return audioName; + } +} diff --git a/src/main/java/org/telegram/api/methods/SendChatAction.java b/src/main/java/org/telegram/api/methods/SendChatAction.java new file mode 100644 index 00000000..f1700008 --- /dev/null +++ b/src/main/java/org/telegram/api/methods/SendChatAction.java @@ -0,0 +1,86 @@ +package org.telegram.api.methods; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method when you need to tell the user that something is happening on the bot's side. + * The status is set for 5 seconds or less (when a message arrives from your bot, + * Telegram clients clear its typing status). + * @date 20 of June of 2015 + */ +public class SendChatAction extends BotApiMethod{ + + public static final String PATH = "sendChatAction"; + + public static final String CHATID_FIELD = "chat_id"; + private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) + public static final String ACTION_FIELD = "action"; + /** + * Type of action to broadcast. + * Choose one, depending on what the user is about to receive: + * 'typing' for text messages + * 'upload_photo' for photos + * 'record_video' or 'upload_video' for videos + * 'record_audio' or 'upload_audio' for audio files + * 'upload_document' for general files, + * 'find_location' for location data. + */ + private String action; + + public String getChatId() { + return chatId; + } + + public void setChatId(String chatId) { + this.chatId = chatId; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + @Override + public String getPath() { + return PATH; + } + + @Override + public Boolean deserializeResponse(JSONObject answer) { + if (answer.getBoolean("ok")) { + return answer.getBoolean("result"); + } + return null; + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(CHATID_FIELD, chatId); + jsonObject.put(ACTION_FIELD, action); + return jsonObject; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(CHATID_FIELD, chatId); + gen.writeStringField(ACTION_FIELD, action); + gen.writeEndObject(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/methods/SendDocument.java b/src/main/java/org/telegram/api/methods/SendDocument.java new file mode 100644 index 00000000..0345d66a --- /dev/null +++ b/src/main/java/org/telegram/api/methods/SendDocument.java @@ -0,0 +1,76 @@ +package org.telegram.api.methods; + +import org.telegram.api.objects.ReplyKeyboard; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to send general files. On success, the sent Message is returned. + * @date 20 of June of 2015 + */ +public class SendDocument { + public static final String PATH = "senddocument"; + + public static final String CHATID_FIELD = "chat_id"; + private String chatId; ///< Unique identifier for the chat to send the message to or Username for the channel to send the message to + public static final String DOCUMENT_FIELD = "document"; + private String document; ///< File file to send. file_id as String to resend a file that is already on the Telegram servers + public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id"; + private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message + public static final String REPLYMARKUP_FIELD = "reply_markup"; + private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard + + private boolean isNewDocument; + private String documentName; + + public SendDocument() { + super(); + } + + public String getChatId() { + return chatId; + } + + public void setChatId(String chatId) { + this.chatId = chatId; + } + + public String getDocument() { + return document; + } + + public void setDocument(String document) { + this.document = document; + this.isNewDocument = false; + } + + public void setNewDocument(String document, String documentName) { + this.document = document; + this.isNewDocument = true; + this.documentName = documentName; + } + + public boolean isNewDocument() { + return isNewDocument; + } + + public String getDocumentName() { + return documentName; + } + + public Integer getReplayToMessageId() { + return replayToMessageId; + } + + public void setReplayToMessageId(Integer replayToMessageId) { + this.replayToMessageId = replayToMessageId; + } + + public ReplyKeyboard getReplayMarkup() { + return replayMarkup; + } + + public void setReplayMarkup(ReplyKeyboard replayMarkup) { + this.replayMarkup = replayMarkup; + } +} diff --git a/src/main/java/org/telegram/api/methods/SendLocation.java b/src/main/java/org/telegram/api/methods/SendLocation.java new file mode 100644 index 00000000..9e04b372 --- /dev/null +++ b/src/main/java/org/telegram/api/methods/SendLocation.java @@ -0,0 +1,123 @@ +package org.telegram.api.methods; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.objects.Message; +import org.telegram.api.objects.ReplyKeyboard; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to send point on the map. On success, the sent Message is returned. + * @date 20 of June of 2015 + */ +public class SendLocation extends BotApiMethod { + public static final String PATH = "sendlocation"; + + public static final String CHATID_FIELD = "chat_id"; + private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) + public static final String LATITUDE_FIELD = "latitude"; + private Float latitude; ///< Latitude of location + public static final String LONGITUDE_FIELD = "longitude"; + private Float longitude; ///< Longitude of location + public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id"; + private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message + public static final String REPLYMARKUP_FIELD = "reply_markup"; + private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard + + public String getChatId() { + return chatId; + } + + public void setChatId(String chatId) { + this.chatId = chatId; + } + + public Float getLatitude() { + return latitude; + } + + public void setLatitude(Float latitude) { + this.latitude = latitude; + } + + public Float getLongitude() { + return longitude; + } + + public void setLongitude(Float longitude) { + this.longitude = longitude; + } + + public Integer getReplayToMessageId() { + return replayToMessageId; + } + + public void setReplayToMessageId(Integer replayToMessageId) { + this.replayToMessageId = replayToMessageId; + } + + public ReplyKeyboard getReplayMarkup() { + return replayMarkup; + } + + public void setReplayMarkup(ReplyKeyboard replayMarkup) { + this.replayMarkup = replayMarkup; + } + + @Override + public String getPath() { + return PATH; + } + + @Override + public Message deserializeResponse(JSONObject answer) { + if (answer.getBoolean("ok")) { + return new Message(answer.getJSONObject("result")); + } + return null; + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(CHATID_FIELD, chatId); + jsonObject.put(LATITUDE_FIELD, latitude); + jsonObject.put(LONGITUDE_FIELD, longitude); + if (replayToMessageId != null) { + jsonObject.put(REPLYTOMESSAGEID_FIELD, replayToMessageId); + } + if (replayMarkup != null) { + jsonObject.put(REPLYMARKUP_FIELD, replayMarkup.toJson()); + } + + return jsonObject; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(METHOD_FIELD, PATH); + gen.writeStringField(CHATID_FIELD, chatId); + gen.writeNumberField(LATITUDE_FIELD, latitude); + gen.writeNumberField(LONGITUDE_FIELD, longitude); + if (replayToMessageId != null) { + gen.writeNumberField(REPLYTOMESSAGEID_FIELD, replayToMessageId); + } + if (replayMarkup != null) { + gen.writeObjectField(REPLYMARKUP_FIELD, replayMarkup); + } + + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/methods/SendMessage.java b/src/main/java/org/telegram/api/methods/SendMessage.java new file mode 100644 index 00000000..3a4741ec --- /dev/null +++ b/src/main/java/org/telegram/api/methods/SendMessage.java @@ -0,0 +1,148 @@ +package org.telegram.api.methods; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.objects.Message; +import org.telegram.api.objects.ReplyKeyboard; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to send text messages. On success, the sent Message is returned. + * @date 20 of June of 2015 + */ +public class SendMessage extends BotApiMethod { + public static final String PATH = "sendmessage"; + + public static final String CHATID_FIELD = "chat_id"; + private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) + public static final String TEXT_FIELD = "text"; + private String text; ///< Text of the message to be sent + public static final String PARSEMODE_FIELD = "parse_mode"; + private String parseMode; ///< Optional. Send Markdown, if you want Telegram apps to show bold, italic and URL text in your bot's message. + public static final String DISABLEWEBPAGEPREVIEW_FIELD = "disable_web_page_preview"; + private Boolean disableWebPagePreview; ///< Optional. Disables link previews for links in this message + public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id"; + private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message + public static final String REPLYMARKUP_FIELD = "reply_markup"; + private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard + + public SendMessage() { + super(); + } + + public String getChatId() { + return chatId; + } + + public void setChatId(String chatId) { + this.chatId = chatId; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public Integer getReplayToMessageId() { + return replayToMessageId; + } + + public void setReplayToMessageId(Integer replayToMessageId) { + this.replayToMessageId = replayToMessageId; + } + + public ReplyKeyboard getReplayMarkup() { + return replayMarkup; + } + + public void setReplayMarkup(ReplyKeyboard replayMarkup) { + this.replayMarkup = replayMarkup; + } + + public Boolean getDisableWebPagePreview() { + return disableWebPagePreview; + } + + public void setDisableWebPagePreview(Boolean disableWebPagePreview) { + this.disableWebPagePreview = disableWebPagePreview; + } + + public void enableMarkdown(boolean enable) { + if (enable) { + this.parseMode = "Markdown"; + } else { + this.parseMode = null; + } + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(CHATID_FIELD, chatId); + jsonObject.put(TEXT_FIELD, text); + if (parseMode != null) { + jsonObject.put(PARSEMODE_FIELD, parseMode); + } + if (disableWebPagePreview != null) { + jsonObject.put(DISABLEWEBPAGEPREVIEW_FIELD, disableWebPagePreview); + } + if (replayToMessageId != null) { + jsonObject.put(REPLYTOMESSAGEID_FIELD, replayToMessageId); + } + if (replayMarkup != null) { + jsonObject.put(REPLYMARKUP_FIELD, replayMarkup.toJson()); + } + + return jsonObject; + } + + @Override + public String getPath() { + return PATH; + } + + @Override + public Message deserializeResponse(JSONObject answer) { + if (answer.getBoolean("ok")) { + return new Message(answer.getJSONObject("result")); + } + return null; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(METHOD_FIELD, PATH); + gen.writeStringField(CHATID_FIELD, chatId); + gen.writeStringField(TEXT_FIELD, text); + + if (parseMode != null) { + gen.writeStringField(PARSEMODE_FIELD, parseMode); + } + if (disableWebPagePreview != null) { + gen.writeBooleanField(DISABLEWEBPAGEPREVIEW_FIELD, disableWebPagePreview); + } + if (replayToMessageId != null) { + gen.writeNumberField(REPLYTOMESSAGEID_FIELD, replayToMessageId); + } + if (replayMarkup != null) { + gen.writeObjectField(REPLYMARKUP_FIELD, replayMarkup); + } + + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/methods/SendPhoto.java b/src/main/java/org/telegram/api/methods/SendPhoto.java new file mode 100644 index 00000000..af128a98 --- /dev/null +++ b/src/main/java/org/telegram/api/methods/SendPhoto.java @@ -0,0 +1,87 @@ +package org.telegram.api.methods; + +import org.telegram.api.objects.ReplyKeyboard; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to send photos. On success, the sent Message is returned. + * @date 20 of June of 2015 + */ +public class SendPhoto { + public static final String PATH = "sendphoto"; + + public static final String CHATID_FIELD = "chat_id"; + private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) + public static final String PHOTO_FIELD = "photo"; + private String photo; ///< Photo to send. file_id as String to resend a photo that is already on the Telegram servers + public static final String CAPTION_FIELD = "photo"; + private String caption; ///< Optional Photo caption (may also be used when resending photos by file_id). + public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id"; + private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message + public static final String REPLYMARKUP_FIELD = "reply_markup"; + private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard + + private boolean isNewPhoto; ///< True if the photo must be uploaded from a file, file if it is a fileId + private String photoName; ///< Name of the photo + + + public SendPhoto() { + super(); + } + + public String getChatId() { + return chatId; + } + + public void setChatId(String chatId) { + this.chatId = chatId; + } + + public String getPhoto() { + return photo; + } + + public String getCaption() { + return caption; + } + + public void setCaption(String caption) { + this.caption = caption; + } + + public Integer getReplayToMessageId() { + return replayToMessageId; + } + + public void setReplayToMessageId(Integer replayToMessageId) { + this.replayToMessageId = replayToMessageId; + } + + public ReplyKeyboard getReplayMarkup() { + return replayMarkup; + } + + public void setReplayMarkup(ReplyKeyboard replayMarkup) { + this.replayMarkup = replayMarkup; + } + + public boolean isNewPhoto() { + return isNewPhoto; + } + + public String getPhotoName() { + return photoName; + } + + public void setPhoto(String photo) { + this.photo = photo; + this.isNewPhoto = false; + } + + public void setNewPhoto(String photo, String photoName) { + this.photo = photo; + this.isNewPhoto = true; + this.photoName = photoName; + } +} diff --git a/src/main/java/org/telegram/api/methods/SendSticker.java b/src/main/java/org/telegram/api/methods/SendSticker.java new file mode 100644 index 00000000..5e9ed96f --- /dev/null +++ b/src/main/java/org/telegram/api/methods/SendSticker.java @@ -0,0 +1,76 @@ +package org.telegram.api.methods; + +import org.telegram.api.objects.ReplyKeyboard; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief TODO + * @date 20 of June of 2015 + */ +public class SendSticker { + public static final String PATH = "sendsticker"; + + public static final String CHATID_FIELD = "chat_id"; + private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) + public static final String STICKER_FIELD = "sticker"; + private String sticker; ///< Sticker file to send. file_id as String to resend a sticker that is already on the Telegram servers + public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id"; + private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message + public static final String REPLYMARKUP_FIELD = "reply_markup"; + private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard + + private boolean isNewSticker; + private String stickerName; + + public SendSticker() { + super(); + } + + public String getChatId() { + return chatId; + } + + public void setChatId(String chatId) { + this.chatId = chatId; + } + + public String getSticker() { + return sticker; + } + + public Integer getReplayToMessageId() { + return replayToMessageId; + } + + public void setReplayToMessageId(Integer replayToMessageId) { + this.replayToMessageId = replayToMessageId; + } + + public ReplyKeyboard getReplayMarkup() { + return replayMarkup; + } + + public void setReplayMarkup(ReplyKeyboard replayMarkup) { + this.replayMarkup = replayMarkup; + } + + public void setSticker(String sticker) { + this.sticker = sticker; + this.isNewSticker = false; + } + + public void setSticker(String sticker, String stickerName) { + this.sticker = sticker; + this.isNewSticker = true; + this.stickerName = stickerName; + } + + public boolean isNewSticker() { + return isNewSticker; + } + + public String getStickerName() { + return stickerName; + } +} diff --git a/src/main/java/org/telegram/api/methods/SendVideo.java b/src/main/java/org/telegram/api/methods/SendVideo.java new file mode 100644 index 00000000..02dbd770 --- /dev/null +++ b/src/main/java/org/telegram/api/methods/SendVideo.java @@ -0,0 +1,98 @@ +package org.telegram.api.methods; + +import org.telegram.api.objects.ReplyKeyboard; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to send video files, + * Telegram clients support mp4 videos (other formats may be sent as Document). + * On success, the sent Message is returned. + * @date 20 of June of 2015 + */ +public class SendVideo { + public static final String PATH = "sendvideo"; + + public static final String CHATID_FIELD = "chat_id"; + private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) + public static final String VIDEO_FIELD = "video"; + private String video; ///< Video to send. file_id as String to resend a video that is already on the Telegram servers + public static final String DURATION_FIELD = "duration"; + private Integer duration; ///< Optional. Duration of sent video in seconds + public static final String CAPTION_FIELD = "caption"; + private String caption; ///< OptionaL. Video caption (may also be used when resending videos by file_id). + public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id"; + private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message + public static final String REPLYMARKUP_FIELD = "reply_markup"; + private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard + + private boolean isNewVideo; ///< True to upload a new video, false to use a fileId + private String videoName; ///< Name of the video + + public SendVideo() { + super(); + } + + public String getChatId() { + return chatId; + } + + public void setChatId(String chatId) { + this.chatId = chatId; + } + + public String getVideo() { + return video; + } + + public Integer getDuration() { + return duration; + } + + public void setDuration(Integer duration) { + this.duration = duration; + } + + public String getCaption() { + return caption; + } + + public void setCaption(String caption) { + this.caption = caption; + } + + public Integer getReplayToMessageId() { + return replayToMessageId; + } + + public void setReplayToMessageId(Integer replayToMessageId) { + this.replayToMessageId = replayToMessageId; + } + + public ReplyKeyboard getReplayMarkup() { + return replayMarkup; + } + + public void setReplayMarkup(ReplyKeyboard replayMarkup) { + this.replayMarkup = replayMarkup; + } + + public boolean isNewVideo() { + return isNewVideo; + } + + public String getVideoName() { + return videoName; + } + + public void setVideo(String video) { + this.video = video; + this.isNewVideo = false; + } + + public void setNewVideo(String video, String videoName) { + this.video = video; + this.isNewVideo = true; + this.videoName = videoName; + } +} diff --git a/src/main/java/org/telegram/api/methods/SendVoice.java b/src/main/java/org/telegram/api/methods/SendVoice.java new file mode 100644 index 00000000..d8501df1 --- /dev/null +++ b/src/main/java/org/telegram/api/methods/SendVoice.java @@ -0,0 +1,31 @@ +package org.telegram.api.methods; + +import org.telegram.api.objects.ReplyKeyboard; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to send voice notes, if you want Telegram clients to display + * the file as a playable voice message. + * For this to work, your audio must be in an .ogg file encoded with OPUS + * (other formats may be sent as Audio or Document). + * @date 16 of July of 2015 + */ +public class SendVoice { + public static final String PATH = "sendvoice"; + + public static final String CHATID_FIELD = "chat_id"; + private String chatId; ///< Unique identifier for the chat sent message to (Or username for channels) + public static final String AUDIO_FIELD = "audio"; + private String audio; ///< Audio file to send. file_id as String to resend an audio that is already on the Telegram servers + public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id"; + private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message + public static final String REPLYMARKUP_FIELD = "reply_markup"; + private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard + public static final String DURATION_FIELD = "duration"; + private Integer duration; ///< Optional. Duration of sent audio in seconds + + public SendVoice() { + super(); + } +} diff --git a/src/main/java/org/telegram/api/methods/SetWebhook.java b/src/main/java/org/telegram/api/methods/SetWebhook.java new file mode 100644 index 00000000..5da3ab59 --- /dev/null +++ b/src/main/java/org/telegram/api/methods/SetWebhook.java @@ -0,0 +1,39 @@ +package org.telegram.api.methods; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Use this method to specify a url and receive incoming updates via an outgoing webhook. + * Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, + * containing a JSON-serialized Update. In case of an unsuccessful request, + * we will give up after a reasonable amount of attempts. + * @date 20 of June of 2015 + */ +public class SetWebhook { + public static final String PATH = "setwebhook"; + + public static final String URL_FIELD = "url"; + private String url; ///< Optional. HTTPS url to send updates to. Use an empty string to remove webhook integration + public static final String CERTIFICATE_FIELD = "certificate"; + private String certificateFile; ///< Optional. Upload your public key certificate so that the root certificate in use can be checked + + public SetWebhook() { + this.url = ""; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getCertificateFile() { + return certificateFile; + } + + public void setCertificateFile(String certificateFile) { + this.certificateFile = certificateFile; + } +} diff --git a/src/main/java/org/telegram/api/objects/Audio.java b/src/main/java/org/telegram/api/objects/Audio.java new file mode 100644 index 00000000..5ca8ec72 --- /dev/null +++ b/src/main/java/org/telegram/api/objects/Audio.java @@ -0,0 +1,134 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents an audio file + * @date 16 of July of 2015 + */ +public class Audio implements BotApiObject { + + public static final String FILEID_FIELD = "file_id"; + @JsonProperty(FILEID_FIELD) + private String fileId; ///< Unique identifier for this file + public static final String DURATION_FIELD = "duration"; + @JsonProperty(DURATION_FIELD) + private Integer duration; ///< Integer Duration of the audio in seconds as defined by sender + public static final String MIMETYPE_FIELD = "mime_type"; + @JsonProperty(MIMETYPE_FIELD) + private String mimeType; ///< Optional. MIME type of the file as defined by sender + public static final String FILESIZE_FIELD = "file_size"; + @JsonProperty(FILESIZE_FIELD) + private Integer fileSize; ///< Optional. File size + public static final String TITLE_FIELD = "title"; + @JsonProperty(TITLE_FIELD) + private String title; ///< Optional. Title of the audio as defined by sender or by audio tags + public static final String PERFORMER_FIELD = "performer"; + @JsonProperty(PERFORMER_FIELD) + private String performer; ///< Optional. Performer of the audio as defined by sender or by audio tags + + public Audio() { + super(); + } + + public Audio(JSONObject jsonObject) { + super(); + this.fileId = jsonObject.getString(FILEID_FIELD); + this.duration = jsonObject.getInt(DURATION_FIELD); + if (jsonObject.has(MIMETYPE_FIELD)) { + this.mimeType = jsonObject.getString(MIMETYPE_FIELD); + } + if (jsonObject.has(FILEID_FIELD)) { + this.fileSize = jsonObject.getInt(FILESIZE_FIELD); + } + if (jsonObject.has(TITLE_FIELD)) { + this.title = jsonObject.getString(TITLE_FIELD); + } + if (jsonObject.has(PERFORMER_FIELD)) { + this.performer = jsonObject.getString(PERFORMER_FIELD); + } + } + + public String getFileId() { + return fileId; + } + + public void setFileId(String fileId) { + this.fileId = fileId; + } + + public Integer getDuration() { + return duration; + } + + public void setDuration(Integer duration) { + this.duration = duration; + } + + public String getMimeType() { + return mimeType; + } + + public void setMimeType(String mimeType) { + this.mimeType = mimeType; + } + + public Integer getFileSize() { + return fileSize; + } + + public void setFileSize(Integer fileSize) { + this.fileSize = fileSize; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getPerformer() { + return performer; + } + + public void setPerformer(String performer) { + this.performer = performer; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(FILEID_FIELD, fileId); + gen.writeNumberField(DURATION_FIELD, duration); + if (mimeType != null) { + gen.writeStringField(MIMETYPE_FIELD, mimeType); + } + if (fileSize != null) { + gen.writeNumberField(FILESIZE_FIELD, fileSize); + } + if (title != null) { + gen.writeStringField(TITLE_FIELD, title); + } + if (performer != null) { + gen.writeStringField(PERFORMER_FIELD, performer); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/Chat.java b/src/main/java/org/telegram/api/objects/Chat.java new file mode 100644 index 00000000..68acd0c3 --- /dev/null +++ b/src/main/java/org/telegram/api/objects/Chat.java @@ -0,0 +1,129 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents a Telegram chat with an user or a group + * @date 24 of June of 2015 + */ +public class Chat implements BotApiObject { + private static final String USERCHATTYPE = "private"; + private static final String GROUPCHATTYPE = "group"; + private static final String CHANNELCHATTYPE = "channel"; + private static final String SUPERGROUPCHATTYPE = "supergroup"; + + public static final String ID_FIELD = "id"; + @JsonProperty(ID_FIELD) + private Long id; ///< Unique identifier for this chat, not exciding 1e13 by absolute value + public static final String TYPE_FIELD = "type"; + @JsonProperty(TYPE_FIELD) + private String type; ///< Type of the chat, one of “private”, “group” or “channel” + public static final String TITLE_FIELD = "title"; + @JsonProperty(TITLE_FIELD) + private String title; ///< Optional. Title of the chat, only for channels and group chat + public static final String FIRSTNAME_FIELD = "first_name"; + @JsonProperty(FIRSTNAME_FIELD) + private String firstName; ///< Optional. Username of the chat, only for private chats and channels if available + public static final String LASTNAME_FIELD = "last_name"; + @JsonProperty(LASTNAME_FIELD) + private String lastName; ///< Optional. Interlocutor's first name for private chats + public static final String USERNAME_FIELD = "username"; + @JsonProperty(USERNAME_FIELD) + private String userName; ///< Optional. Interlocutor's last name for private chats + + public Chat() { + super(); + } + + public Chat(JSONObject jsonObject) { + super(); + this.id = jsonObject.getLong(ID_FIELD); + this.type = jsonObject.getString(TYPE_FIELD); + if (jsonObject.has(TITLE_FIELD)) { + this.title = jsonObject.getString(TITLE_FIELD); + } + if (jsonObject.has(FIRSTNAME_FIELD)) { + this.firstName = jsonObject.getString(FIRSTNAME_FIELD); + } + if (jsonObject.has(LASTNAME_FIELD)) { + this.lastName = jsonObject.getString(LASTNAME_FIELD); + } + if (jsonObject.has(USERNAME_FIELD)) { + this.userName = jsonObject.getString(USERNAME_FIELD); + } + } + + public Long getId() { + return id; + } + + public Boolean isGroupChat() { + return GROUPCHATTYPE.equals(type); + } + + public Boolean isChannelChat() { + return CHANNELCHATTYPE.equals(type); + } + + public Boolean isUserChat() { + return USERCHATTYPE.equals(type); + } + + public Boolean isSuperGroupChat() { + return SUPERGROUPCHATTYPE.equals(type); + } + + public String getTitle() { + return title; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public String getUserName() { + return userName; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeNumberField(ID_FIELD, id); + gen.writeStringField(TYPE_FIELD, type); + if (isUserChat()) { + if (firstName != null) { + gen.writeStringField(FIRSTNAME_FIELD, firstName); + } + if (lastName != null) { + gen.writeStringField(LASTNAME_FIELD, lastName); + } + } else { + if (title != null) { + gen.writeStringField(TITLE_FIELD, title); + } + } + if (!isGroupChat() && userName != null) { + gen.writeStringField(USERNAME_FIELD, userName); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/ChosenInlineQuery.java b/src/main/java/org/telegram/api/objects/ChosenInlineQuery.java new file mode 100644 index 00000000..c7d7d666 --- /dev/null +++ b/src/main/java/org/telegram/api/objects/ChosenInlineQuery.java @@ -0,0 +1,66 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents a result of an inline query that was chosen by the user and sent to their chat partner. + * @date 01 of January of 2016 + */ +public class ChosenInlineQuery implements BotApiObject { + public static final String RESULTID_FIELD = "id"; + @JsonProperty(RESULTID_FIELD) + private String resultId; ///< The unique identifier for the result that was chosen. + public static final String FROM_FIELD = "from"; + @JsonProperty(FROM_FIELD) + private User from; ///< The user that chose the result. + public static final String QUERY_FIELD = "query"; + @JsonProperty(QUERY_FIELD) + private String query; ///< The query that was used to obtain the result. + + public ChosenInlineQuery() { + super(); + } + + public ChosenInlineQuery(JSONObject jsonObject) { + super(); + this.resultId = jsonObject.getString(RESULTID_FIELD); + this.from = new User(jsonObject.getJSONObject(FROM_FIELD)); + this.query = jsonObject.getString(QUERY_FIELD); + } + + public String getResultId() { + return resultId; + } + + public User getFrom() { + return from; + } + + public String getQuery() { + return query; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(RESULTID_FIELD, resultId); + gen.writeObjectField(FROM_FIELD, from); + gen.writeStringField(QUERY_FIELD, query); + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/Contact.java b/src/main/java/org/telegram/api/objects/Contact.java new file mode 100644 index 00000000..499fbbeb --- /dev/null +++ b/src/main/java/org/telegram/api/objects/Contact.java @@ -0,0 +1,68 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents a phone contact. + * @date 20 of June of 2015 + */ +public class Contact implements BotApiObject { + + public static final String PHONENUMBER_FIELD = "phone_number"; + @JsonProperty(PHONENUMBER_FIELD) + private String phoneNumber; ///< Contact's phone number + public static final String FIRSTNAME_FIELD = "first_name"; + @JsonProperty(FIRSTNAME_FIELD) + private String firstName; ///< Contact's first name + public static final String LASTNAME_FIELD = "last_name"; + @JsonProperty(LASTNAME_FIELD) + private String lastName; ///< Optional. Contact's last name + public static final String USERID_FIELD = "user_id"; + @JsonProperty(USERID_FIELD) + private Integer userID; ///< Optional. Contact's user identifier in Telegram + + public Contact() { + super(); + } + + public Contact(JSONObject jsonObject) { + super(); + this.phoneNumber = jsonObject.getString(PHONENUMBER_FIELD); + this.firstName = jsonObject.getString(FIRSTNAME_FIELD); + if (jsonObject.has(LASTNAME_FIELD)) { + this.lastName = jsonObject.getString(LASTNAME_FIELD); + } + if (jsonObject.has(USERID_FIELD)) { + this.userID = jsonObject.getInt(USERID_FIELD); + } + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(PHONENUMBER_FIELD, phoneNumber); + gen.writeStringField(FIRSTNAME_FIELD, firstName); + if (lastName != null) { + gen.writeStringField(LASTNAME_FIELD, lastName); + } + if (userID != null) { + gen.writeNumberField(USERID_FIELD, userID); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/Document.java b/src/main/java/org/telegram/api/objects/Document.java new file mode 100644 index 00000000..e46242d9 --- /dev/null +++ b/src/main/java/org/telegram/api/objects/Document.java @@ -0,0 +1,119 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents a general file (as opposed to photos and audio files). + * Telegram users can send files of any type of up to 1.5 GB in size. + * @date 20 of June of 2015 + */ +public class Document implements BotApiObject { + + public static final String FILEID_FIELD = "file_id"; + @JsonProperty(FILEID_FIELD) + private String fileId; ///< Unique identifier for this file + public static final String THUMB_FIELD = "thumb"; + @JsonProperty(THUMB_FIELD) + private PhotoSize thumb; ///< Document thumbnail as defined by sender + public static final String FILENAME_FIELD = "file_name"; + @JsonProperty(FILENAME_FIELD) + private String fileName; ///< Optional. Original filename as defined by sender + public static final String MIMETYPE_FIELD = "mime_type"; + @JsonProperty(MIMETYPE_FIELD) + private String mimeType; ///< Optional. Mime type of a file as defined by sender + public static final String FILESIZE_FIELD = "file_size"; + @JsonProperty(FILESIZE_FIELD) + private Integer fileSize; ///< Optional. File size + + public Document() { + super(); + } + + public Document(JSONObject jsonObject) { + this.fileId = jsonObject.getString(FILEID_FIELD); + if (jsonObject.has(THUMB_FIELD)) { + this.thumb = new PhotoSize(jsonObject.getJSONObject(THUMB_FIELD)); + } + if (jsonObject.has(FILENAME_FIELD)) { + this.fileName = jsonObject.getString(FILENAME_FIELD); + } + if (jsonObject.has(MIMETYPE_FIELD)) { + this.mimeType = jsonObject.getString(MIMETYPE_FIELD); + } + if (jsonObject.has(FILESIZE_FIELD)) { + this.fileSize = jsonObject.getInt(FILESIZE_FIELD); + } + } + + public String getFileId() { + return fileId; + } + + public void setFileId(String fileId) { + this.fileId = fileId; + } + + public PhotoSize getThumb() { + return thumb; + } + + public void setThumb(PhotoSize thumb) { + this.thumb = thumb; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getMimeType() { + return mimeType; + } + + public void setMimeType(String mimeType) { + this.mimeType = mimeType; + } + + public Integer getFileSize() { + return fileSize; + } + + public void setFileSize(Integer fileSize) { + this.fileSize = fileSize; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(FILEID_FIELD, fileId); + gen.writeObjectField(THUMB_FIELD, thumb); + if (fileName != null) { + gen.writeStringField(FILENAME_FIELD, fileName); + } + if (mimeType != null) { + gen.writeStringField(MIMETYPE_FIELD, mimeType); + } + if (fileSize != null) { + gen.writeNumberField(FILESIZE_FIELD, fileSize); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/File.java b/src/main/java/org/telegram/api/objects/File.java new file mode 100644 index 00000000..1715aec2 --- /dev/null +++ b/src/main/java/org/telegram/api/objects/File.java @@ -0,0 +1,86 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents a file ready to be downloaded + * @date 24 of June of 2015 + */ +public class File implements BotApiObject { + public static final String FILE_ID = "file_id"; + @JsonProperty(FILE_ID) + private String fileId; ///< Unique identifier for this file + public static final String FILE_SIZE_FIELD = "file_size"; + @JsonProperty(FILE_SIZE_FIELD) + private Integer fileSize; ///< Optional. File size, if known + public static final String FILE_PATH_FIELD = "first_name"; + @JsonProperty(FILE_PATH_FIELD) + private String filePath; ///< Optional. File path. Use https://api.telegram.org/file/bot/ to get the file. + + public File() { + super(); + } + + public File(JSONObject jsonObject) { + super(); + this.fileId = jsonObject.getString(FILE_ID); + if (jsonObject.has(FILE_SIZE_FIELD)) { + this.fileSize = jsonObject.getInt(FILE_SIZE_FIELD); + } + if (jsonObject.has(FILE_PATH_FIELD)) { + this.filePath = jsonObject.getString(FILE_PATH_FIELD); + } + } + + public String getFileId() { + return fileId; + } + + public void setFileId(String fileId) { + this.fileId = fileId; + } + + public Integer getFileSize() { + return fileSize; + } + + public void setFileSize(Integer fileSize) { + this.fileSize = fileSize; + } + + public String getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(FILE_ID, fileId); + if (fileSize != null) { + gen.writeNumberField(FILE_SIZE_FIELD, fileSize); + } + if (filePath != null) { + gen.writeStringField(FILE_PATH_FIELD, filePath); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/ForceReplyKeyboard.java b/src/main/java/org/telegram/api/objects/ForceReplyKeyboard.java new file mode 100644 index 00000000..18ede017 --- /dev/null +++ b/src/main/java/org/telegram/api/objects/ForceReplyKeyboard.java @@ -0,0 +1,94 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Upon receiving a message with this object, Telegram clients will display a reply interface to the user + * (act as if the user has selected the bot‘s message and tapped ’Reply'). + * This can be extremely useful if you want to create user-friendly step-by-step + * interfaces without having to sacrifice privacy mode. + * @date 22 of June of 2015 + */ +public class ForceReplyKeyboard implements ReplyKeyboard { + + public static final String FORCEREPLY_FIELD = "force_reply"; + /** + * Shows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply' + */ + @JsonProperty(FORCEREPLY_FIELD) + private Boolean forceReply; + public static final String SELECTIVE_FIELD = "selective"; + /** + * Use this parameter if you want to force reply from specific users only. + * Targets: + * 1) users that are @mentioned in the text of the Message object; + * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. + */ + @JsonProperty(SELECTIVE_FIELD) + private Boolean selective; + + public ForceReplyKeyboard() { + super(); + this.forceReply = true; + } + + public ForceReplyKeyboard(JSONObject jsonObject) { + super(); + if (jsonObject.has(FORCEREPLY_FIELD)) { + this.forceReply = jsonObject.getBoolean(FORCEREPLY_FIELD); + } + if (jsonObject.has(SELECTIVE_FIELD)) { + this.selective = jsonObject.getBoolean(SELECTIVE_FIELD); + } + } + + public Boolean getForceReply() { + return forceReply; + } + + public void setForceReply(Boolean forceReply) { + this.forceReply = forceReply; + } + + public Boolean getSelective() { + return selective; + } + + public void setSelective(Boolean selective) { + this.selective = selective; + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + + jsonObject.put(FORCEREPLY_FIELD, this.forceReply); + if (this.selective != null) { + jsonObject.put(SELECTIVE_FIELD, this.selective); + } + + return jsonObject; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeBooleanField(FORCEREPLY_FIELD, forceReply); + gen.writeBooleanField(SELECTIVE_FIELD, selective); + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/InlineQuery.java b/src/main/java/org/telegram/api/objects/InlineQuery.java new file mode 100644 index 00000000..0a6f3a47 --- /dev/null +++ b/src/main/java/org/telegram/api/objects/InlineQuery.java @@ -0,0 +1,76 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents an incoming inline query. + * When the user sends an empty query, your bot could return some default or trending results. + * @date 01 of January of 2016 + */ +public class InlineQuery implements BotApiObject { + public static final String ID_FIELD = "id"; + @JsonProperty(ID_FIELD) + private String id; ///< Unique identifier for this query + public static final String FROM_FIELD = "from"; + @JsonProperty(FROM_FIELD) + private User from; ///< Sender + public static final String QUERY_FIELD = "query"; + @JsonProperty(QUERY_FIELD) + private String query; ///< Text of the query + public static final String OFFSET_FIELD = "offset"; + @JsonProperty(OFFSET_FIELD) + private String offset; ///< Offset of the results to be returned, can be controlled by the bot + + public InlineQuery() { + super(); + } + + public InlineQuery(JSONObject jsonObject) { + super(); + this.id = jsonObject.getString(ID_FIELD); + this.from = new User(jsonObject.getJSONObject(FROM_FIELD)); + this.query = jsonObject.getString(QUERY_FIELD); + this.offset = jsonObject.getString(OFFSET_FIELD); + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(ID_FIELD, id); + gen.writeObjectField(FROM_FIELD, from); + gen.writeStringField(QUERY_FIELD, query); + gen.writeStringField(OFFSET_FIELD, offset); + gen.writeEndObject(); + gen.flush(); + } + + public String getId() { + return id; + } + + public User getFrom() { + return from; + } + + public String getQuery() { + return query; + } + + public String getOffset() { + return offset; + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/InlineQueryResult.java b/src/main/java/org/telegram/api/objects/InlineQueryResult.java new file mode 100644 index 00000000..8040a193 --- /dev/null +++ b/src/main/java/org/telegram/api/objects/InlineQueryResult.java @@ -0,0 +1,13 @@ +package org.telegram.api.objects; + +import org.telegram.api.interfaces.BotApiObject; +import org.telegram.api.interfaces.IToJson; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents one result of an inline query. + * @date 01 of January of 2016 + */ +public interface InlineQueryResult extends BotApiObject, IToJson { +} diff --git a/src/main/java/org/telegram/api/objects/InlineQueryResultArticle.java b/src/main/java/org/telegram/api/objects/InlineQueryResultArticle.java new file mode 100644 index 00000000..b14b1480 --- /dev/null +++ b/src/main/java/org/telegram/api/objects/InlineQueryResultArticle.java @@ -0,0 +1,233 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Represents a link to an article or web page. + * @date 01 of January of 2016 + */ +public class InlineQueryResultArticle implements InlineQueryResult { + + public static final String TYPE_FIELD = "type"; + @JsonProperty(TYPE_FIELD) + private final String type = "article"; ///< Type of the result, must be “article” + public static final String ID_FIELD = "id"; + @JsonProperty(ID_FIELD) + private String id; ///< Unique identifier of this result + public static final String TITLE_FIELD = "title"; + @JsonProperty(TITLE_FIELD) + private String title; ///< Title of the result + public static final String MESSAGETEXT_FIELD = "message_text"; + @JsonProperty(MESSAGETEXT_FIELD) + private String messageText; ///< Text of a message to be sent + public static final String PARSEMODE_FIELD = "parse_mode"; + @JsonProperty(PARSEMODE_FIELD) + private String parseMode; ///< Optional. Send “Markdown”, if you want Telegram apps to show bold, italic and inline URLs in your bot's message. + public static final String DISABLEWEBPAGEPREVIEW_FIELD = "disable_web_page_preview"; + @JsonProperty(DISABLEWEBPAGEPREVIEW_FIELD) + private Boolean disableWebPagePreview; ///< Optional. Disables link previews for links in the sent message + public static final String URL_FIELD = "url"; + @JsonProperty(URL_FIELD) + private String url; ///< Optional. URL of the result + public static final String HIDEURL_FIELD = "hide_url"; + @JsonProperty(HIDEURL_FIELD) + private Boolean hideUrl; ///< Optional. Pass True, if you don't want the URL to be shown in the message + public static final String DESCRIPTION_FIELD = "description"; + @JsonProperty(DESCRIPTION_FIELD) + private String description; ///< Optional. Short description of the result + public static final String THUMBURL_FIELD = "thumb_url"; + @JsonProperty(THUMBURL_FIELD) + private String thumbUrl; ///< Optional. Url of the thumbnail for the result + public static final String THUMBWIDTH_FIELD = "thumb_width"; + @JsonProperty(THUMBWIDTH_FIELD) + private Integer thumbWidth; ///< Optional. Thumbnail width + public static final String THUMBHEIGHT_FIELD = "thumb_height"; + @JsonProperty(THUMBHEIGHT_FIELD) + private Integer thumbHeight; ///< Optional. Thumbnail height + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getMessageText() { + return messageText; + } + + public void setMessageText(String messageText) { + this.messageText = messageText; + } + + public String getParseMode() { + return parseMode; + } + + public void setParseMode(String parseMode) { + this.parseMode = parseMode; + } + + public void setMarkdown(boolean enabled) { + if (enabled) { + parseMode = "Markdown"; + } else { + parseMode = null; + } + } + + public Boolean getDisableWebPagePreview() { + return disableWebPagePreview; + } + + public void setDisableWebPagePreview(Boolean disableWebPagePreview) { + this.disableWebPagePreview = disableWebPagePreview; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public Boolean getHideUrl() { + return hideUrl; + } + + public void setHideUrl(Boolean hideUrl) { + this.hideUrl = hideUrl; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getThumbUrl() { + return thumbUrl; + } + + public void setThumbUrl(String thumbUrl) { + this.thumbUrl = thumbUrl; + } + + public Integer getThumbWidth() { + return thumbWidth; + } + + public void setThumbWidth(Integer thumbWidth) { + this.thumbWidth = thumbWidth; + } + + public Integer getThumbHeight() { + return thumbHeight; + } + + public void setThumbHeight(Integer thumbHeight) { + this.thumbHeight = thumbHeight; + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + + jsonObject.put(TYPE_FIELD, this.type); + jsonObject.put(ID_FIELD, this.id); + jsonObject.put(TITLE_FIELD, this.title); + jsonObject.put(MESSAGETEXT_FIELD, this.messageText); + if (parseMode != null) { + jsonObject.put(PARSEMODE_FIELD, this.parseMode); + } + if (disableWebPagePreview != null) { + jsonObject.put(DISABLEWEBPAGEPREVIEW_FIELD, this.disableWebPagePreview); + } + if (url != null) { + jsonObject.put(URL_FIELD, this.url); + } + if (hideUrl != null) { + jsonObject.put(HIDEURL_FIELD, this.hideUrl); + } + if (description != null) { + jsonObject.put(DESCRIPTION_FIELD, this.description); + } + if (thumbUrl != null) { + jsonObject.put(THUMBURL_FIELD, this.thumbUrl); + } + if (thumbWidth != null) { + jsonObject.put(THUMBWIDTH_FIELD, this.thumbWidth); + } + if (thumbHeight != null) { + jsonObject.put(THUMBHEIGHT_FIELD, this.thumbHeight); + } + + return jsonObject; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(TYPE_FIELD, type); + gen.writeStringField(ID_FIELD, id); + gen.writeStringField(TITLE_FIELD, title); + gen.writeStringField(MESSAGETEXT_FIELD, messageText); + + if (parseMode != null) { + gen.writeStringField(PARSEMODE_FIELD, this.parseMode); + } + if (disableWebPagePreview != null) { + gen.writeBooleanField(DISABLEWEBPAGEPREVIEW_FIELD, this.disableWebPagePreview); + } + if (url != null) { + gen.writeStringField(URL_FIELD, this.url); + } + if (hideUrl != null) { + gen.writeBooleanField(HIDEURL_FIELD, this.hideUrl); + } + if (description != null) { + gen.writeStringField(DESCRIPTION_FIELD, this.description); + } + if (thumbUrl != null) { + gen.writeStringField(THUMBURL_FIELD, this.thumbUrl); + } + if (thumbWidth != null) { + gen.writeNumberField(THUMBWIDTH_FIELD, this.thumbWidth); + } + if (thumbHeight != null) { + gen.writeNumberField(THUMBHEIGHT_FIELD, this.thumbHeight); + } + + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/InlineQueryResultGif.java b/src/main/java/org/telegram/api/objects/InlineQueryResultGif.java new file mode 100644 index 00000000..af3a82d0 --- /dev/null +++ b/src/main/java/org/telegram/api/objects/InlineQueryResultGif.java @@ -0,0 +1,213 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with optional caption. + * Alternatively, you can provide message_text to send it instead of the animation. + * @date 01 of January of 2016 + */ +public class InlineQueryResultGif implements InlineQueryResult { + + public static final String TYPE_FIELD = "type"; + @JsonProperty(TYPE_FIELD) + private final String type = "gif"; ///< Type of the result, must be "gif" + public static final String ID_FIELD = "id"; + @JsonProperty(ID_FIELD) + private String id; ///< Unique identifier of this result + public static final String GIFURL_FIELD = "gif_url"; + @JsonProperty(GIFURL_FIELD) + private String gifUrl; ///< A valid URL for the GIF file. File size must not exceed 1MB + public static final String GIFWIDTH_FIELD = "gif_width"; + @JsonProperty(GIFWIDTH_FIELD) + private Integer gifWidth; ///< Optional. Width of the GIF + public static final String GIFHEIGHT_FIELD = "gif_height"; + @JsonProperty(GIFHEIGHT_FIELD) + private Integer gifHeight; ///< Optional. Height of the GIF + public static final String THUMBURL_FIELD = "thumb_url"; + @JsonProperty(THUMBURL_FIELD) + private String thumbUrl; ///< Optional. URL of a static thumbnail for the result (jpeg or gif) + public static final String TITLE_FIELD = "title"; + @JsonProperty(TITLE_FIELD) + private String title; ///< Optional. Title for the result + public static final String CAPTION_FIELD = "caption"; + @JsonProperty(CAPTION_FIELD) + private String caption; ///< Optional. Caption of the GIF file to be sent + public static final String MESSAGETEXT_FIELD = "message_text"; + @JsonProperty(MESSAGETEXT_FIELD) + private String messageText; ///< Optional. Text of a message to be sent instead of the animation + public static final String PARSEMODE_FIELD = "parse_mode"; + @JsonProperty(PARSEMODE_FIELD) + private String parseMode; ///< Optional. Send “Markdown”, if you want Telegram apps to show bold, italic and inline URLs in your bot's message. + public static final String DISABLEWEBPAGEPREVIEW_FIELD = "disable_web_page_preview"; + @JsonProperty(DISABLEWEBPAGEPREVIEW_FIELD) + private Boolean disableWebPagePreview; ///< Optional. Disables link previews for links in the sent message + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getMessageText() { + return messageText; + } + + public void setMessageText(String messageText) { + this.messageText = messageText; + } + + public String getParseMode() { + return parseMode; + } + + public void setParseMode(String parseMode) { + this.parseMode = parseMode; + } + + public Boolean getDisableWebPagePreview() { + return disableWebPagePreview; + } + + public void setDisableWebPagePreview(Boolean disableWebPagePreview) { + this.disableWebPagePreview = disableWebPagePreview; + } + + public String getGifUrl() { + return gifUrl; + } + + public void setGifUrl(String gifUrl) { + this.gifUrl = gifUrl; + } + + public Integer getGifWidth() { + return gifWidth; + } + + public void setGifWidth(Integer gifWidth) { + this.gifWidth = gifWidth; + } + + public Integer getGifHeight() { + return gifHeight; + } + + public void setGifHeight(Integer gifHeight) { + this.gifHeight = gifHeight; + } + + public String getThumbUrl() { + return thumbUrl; + } + + public void setThumbUrl(String thumbUrl) { + this.thumbUrl = thumbUrl; + } + + public String getCaption() { + return caption; + } + + public void setCaption(String caption) { + this.caption = caption; + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + + jsonObject.put(TYPE_FIELD, this.type); + jsonObject.put(ID_FIELD, this.id); + jsonObject.put(GIFURL_FIELD, this.gifUrl); + if (parseMode != null) { + jsonObject.put(PARSEMODE_FIELD, this.parseMode); + } + if (disableWebPagePreview != null) { + jsonObject.put(DISABLEWEBPAGEPREVIEW_FIELD, this.disableWebPagePreview); + } + if (gifWidth != null) { + jsonObject.put(GIFWIDTH_FIELD, this.gifWidth); + } + if (gifHeight != null) { + jsonObject.put(GIFHEIGHT_FIELD, this.gifHeight); + } + if (thumbUrl != null) { + jsonObject.put(THUMBURL_FIELD, this.thumbUrl); + } + if (title != null) { + jsonObject.put(TITLE_FIELD, this.title); + } + if (caption != null) { + jsonObject.put(CAPTION_FIELD, this.caption); + } + if (messageText != null) { + jsonObject.put(MESSAGETEXT_FIELD, this.messageText); + } + + return jsonObject; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(TYPE_FIELD, type); + gen.writeStringField(ID_FIELD, id); + gen.writeStringField(GIFURL_FIELD, this.gifUrl); + + if (parseMode != null) { + gen.writeStringField(PARSEMODE_FIELD, this.parseMode); + } + if (disableWebPagePreview != null) { + gen.writeBooleanField(DISABLEWEBPAGEPREVIEW_FIELD, this.disableWebPagePreview); + } + if (gifWidth != null) { + gen.writeNumberField(GIFWIDTH_FIELD, this.gifWidth); + } + if (gifHeight != null) { + gen.writeNumberField(GIFHEIGHT_FIELD, this.gifHeight); + } + if (thumbUrl != null) { + gen.writeStringField(THUMBURL_FIELD, this.thumbUrl); + } + if (title != null) { + gen.writeStringField(TITLE_FIELD, this.title); + } + if (caption != null) { + gen.writeStringField(CAPTION_FIELD, this.caption); + } + if (messageText != null) { + gen.writeStringField(MESSAGETEXT_FIELD, this.messageText); + } + + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/InlineQueryResultMpeg4Gif.java b/src/main/java/org/telegram/api/objects/InlineQueryResultMpeg4Gif.java new file mode 100644 index 00000000..955650c5 --- /dev/null +++ b/src/main/java/org/telegram/api/objects/InlineQueryResultMpeg4Gif.java @@ -0,0 +1,214 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). + * By default, this animated MPEG-4 file will be sent by the user with optional caption. + * Alternatively, you can provide message_text to send it instead of the animation. + * @date 01 of January of 2016 + */ +public class InlineQueryResultMpeg4Gif implements InlineQueryResult { + + public static final String TYPE_FIELD = "type"; + @JsonProperty(TYPE_FIELD) + private final String type = "mpeg4_gif"; ///< Type of the result, must be "mpeg4_gif" + public static final String ID_FIELD = "id"; + @JsonProperty(ID_FIELD) + private String id; ///< Unique identifier of this result + public static final String MPEG4URL_FIELD = "mpeg4_url"; + @JsonProperty(MPEG4URL_FIELD) + private String mpeg4Url; ///< A valid URL for the MP4 file. File size must not exceed 1MB + public static final String MPEG4WIDTH_FIELD = "mpeg4_width"; + @JsonProperty(MPEG4WIDTH_FIELD) + private Integer mpeg4Width; ///< Optional. Video width + public static final String MPEG4HEIGHT_FIELD = "mpeg4_height"; + @JsonProperty(MPEG4HEIGHT_FIELD) + private Integer mpeg4Height; ///< Optional. Video height + public static final String THUMBURL_FIELD = "thumb_url"; + @JsonProperty(THUMBURL_FIELD) + private String thumbUrl; ///< Optional. URL of the static thumbnail (jpeg or gif) for the result + public static final String TITLE_FIELD = "title"; + @JsonProperty(TITLE_FIELD) + private String title; ///< Optional. Title for the result + public static final String CAPTION_FIELD = "caption"; + @JsonProperty(CAPTION_FIELD) + private String caption; ///< Optional. Caption of the MPEG-4 file to be sent + public static final String MESSAGETEXT_FIELD = "message_text"; + @JsonProperty(MESSAGETEXT_FIELD) + private String messageText; ///< Optional. Text of a message to be sent instead of the animation + public static final String PARSEMODE_FIELD = "parse_mode"; + @JsonProperty(PARSEMODE_FIELD) + private String parseMode; ///< Optional. Send “Markdown”, if you want Telegram apps to show bold, italic and inline URLs in your bot's message. + public static final String DISABLEWEBPAGEPREVIEW_FIELD = "disable_web_page_preview"; + @JsonProperty(DISABLEWEBPAGEPREVIEW_FIELD) + private Boolean disableWebPagePreview; ///< Optional. Disables link previews for links in the sent message + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getMessageText() { + return messageText; + } + + public void setMessageText(String messageText) { + this.messageText = messageText; + } + + public String getParseMode() { + return parseMode; + } + + public void setParseMode(String parseMode) { + this.parseMode = parseMode; + } + + public Boolean getDisableWebPagePreview() { + return disableWebPagePreview; + } + + public void setDisableWebPagePreview(Boolean disableWebPagePreview) { + this.disableWebPagePreview = disableWebPagePreview; + } + + public String getMpeg4Url() { + return mpeg4Url; + } + + public void setMpeg4Url(String mpeg4Url) { + this.mpeg4Url = mpeg4Url; + } + + public Integer getMpeg4Width() { + return mpeg4Width; + } + + public void setMpeg4Width(Integer mpeg4Width) { + this.mpeg4Width = mpeg4Width; + } + + public Integer getMpeg4Height() { + return mpeg4Height; + } + + public void setMpeg4Height(Integer mpeg4Height) { + this.mpeg4Height = mpeg4Height; + } + + public String getThumbUrl() { + return thumbUrl; + } + + public void setThumbUrl(String thumbUrl) { + this.thumbUrl = thumbUrl; + } + + public String getCaption() { + return caption; + } + + public void setCaption(String caption) { + this.caption = caption; + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + + jsonObject.put(TYPE_FIELD, this.type); + jsonObject.put(ID_FIELD, this.id); + jsonObject.put(MPEG4URL_FIELD, this.mpeg4Url); + if (parseMode != null) { + jsonObject.put(PARSEMODE_FIELD, this.parseMode); + } + if (disableWebPagePreview != null) { + jsonObject.put(DISABLEWEBPAGEPREVIEW_FIELD, this.disableWebPagePreview); + } + if (mpeg4Width != null) { + jsonObject.put(MPEG4WIDTH_FIELD, this.mpeg4Width); + } + if (mpeg4Height != null) { + jsonObject.put(MPEG4HEIGHT_FIELD, this.mpeg4Height); + } + if (thumbUrl != null) { + jsonObject.put(THUMBURL_FIELD, this.thumbUrl); + } + if (title != null) { + jsonObject.put(TITLE_FIELD, this.title); + } + if (caption != null) { + jsonObject.put(CAPTION_FIELD, this.caption); + } + if (messageText != null) { + jsonObject.put(MESSAGETEXT_FIELD, this.messageText); + } + + return jsonObject; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(TYPE_FIELD, type); + gen.writeStringField(ID_FIELD, id); + gen.writeStringField(MPEG4URL_FIELD, this.mpeg4Url); + + if (parseMode != null) { + gen.writeStringField(PARSEMODE_FIELD, this.parseMode); + } + if (disableWebPagePreview != null) { + gen.writeBooleanField(DISABLEWEBPAGEPREVIEW_FIELD, this.disableWebPagePreview); + } + if (mpeg4Width != null) { + gen.writeNumberField(MPEG4WIDTH_FIELD, this.mpeg4Width); + } + if (mpeg4Height != null) { + gen.writeNumberField(MPEG4HEIGHT_FIELD, this.mpeg4Height); + } + if (thumbUrl != null) { + gen.writeStringField(THUMBURL_FIELD, this.thumbUrl); + } + if (title != null) { + gen.writeStringField(TITLE_FIELD, this.title); + } + if (caption != null) { + gen.writeStringField(CAPTION_FIELD, this.caption); + } + if (messageText != null) { + gen.writeStringField(MESSAGETEXT_FIELD, this.messageText); + } + + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/InlineQueryResultPhoto.java b/src/main/java/org/telegram/api/objects/InlineQueryResultPhoto.java new file mode 100644 index 00000000..d20cd40e --- /dev/null +++ b/src/main/java/org/telegram/api/objects/InlineQueryResultPhoto.java @@ -0,0 +1,249 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Represents a link to a photo. By default, this photo will be sent by the user with optional caption. + * Alternatively, you can provide message_text to send it instead of photo. + * @date 01 of January of 2016 + */ +public class InlineQueryResultPhoto implements InlineQueryResult { + + public static final String TYPE_FIELD = "type"; + @JsonProperty(TYPE_FIELD) + private final String type = "photo"; ///< Type of the result, must be “photo” + public static final String ID_FIELD = "id"; + @JsonProperty(ID_FIELD) + private String id; ///< Unique identifier of this result + public static final String PHOTOURL_FIELD = "photo_url"; + @JsonProperty(PHOTOURL_FIELD) + private String photoUrl; ///< A valid URL of the photo. Photo size must not exceed 5MB + public static final String MIMETYPE_FIELD = "mime_type"; + @JsonProperty(MIMETYPE_FIELD) + private String mimeType; ///< Optional. MIME type of the photo, defaults to image/jpeg + public static final String PHOTOWIDTH_FIELD = "photo_width"; + @JsonProperty(PHOTOWIDTH_FIELD) + private Integer photoWidth; ///< Optional. Width of the photo + public static final String PHOTOHEIGHT_FIELD = "photo_height"; + @JsonProperty(PHOTOHEIGHT_FIELD) + private Integer photoHeight; ///< Optional. Height of the photo + public static final String THUMBURL_FIELD = "thumb_url"; + @JsonProperty(THUMBURL_FIELD) + private String thumbUrl; ///< Optional. URL of the thumbnail for the photo + public static final String TITLE_FIELD = "title"; + @JsonProperty(TITLE_FIELD) + private String title; ///< Optional. Title for the result + public static final String DESCRIPTION_FIELD = "description"; + @JsonProperty(DESCRIPTION_FIELD) + private String description; ///< Optional. Short description of the result + public static final String CAPTION_FIELD = "caption"; + @JsonProperty(CAPTION_FIELD) + private String caption; ///< Optional. Caption of the photo to be sent + public static final String MESSAGETEXT_FIELD = "message_text"; + @JsonProperty(MESSAGETEXT_FIELD) + private String messageText; ///< Optional. Text of a message to be sent instead of the photo + public static final String PARSEMODE_FIELD = "parse_mode"; + @JsonProperty(PARSEMODE_FIELD) + private String parseMode; ///< Optional. Send “Markdown”, if you want Telegram apps to show bold, italic and inline URLs in your bot's message. + public static final String DISABLEWEBPAGEPREVIEW_FIELD = "disable_web_page_preview"; + @JsonProperty(DISABLEWEBPAGEPREVIEW_FIELD) + private Boolean disableWebPagePreview; ///< Optional. Disables link previews for links in the sent message + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getMessageText() { + return messageText; + } + + public void setMessageText(String messageText) { + this.messageText = messageText; + } + + public String getParseMode() { + return parseMode; + } + + public void setParseMode(String parseMode) { + this.parseMode = parseMode; + } + + public Boolean getDisableWebPagePreview() { + return disableWebPagePreview; + } + + public void setDisableWebPagePreview(Boolean disableWebPagePreview) { + this.disableWebPagePreview = disableWebPagePreview; + } + + public String getPhotoUrl() { + return photoUrl; + } + + public void setPhotoUrl(String photoUrl) { + this.photoUrl = photoUrl; + } + + public String getMimeType() { + return mimeType; + } + + public void setMimeType(String mimeType) { + this.mimeType = mimeType; + } + + public Integer getPhotoWidth() { + return photoWidth; + } + + public void setPhotoWidth(Integer photoWidth) { + this.photoWidth = photoWidth; + } + + public Integer getPhotoHeight() { + return photoHeight; + } + + public void setPhotoHeight(Integer photoHeight) { + this.photoHeight = photoHeight; + } + + public String getThumbUrl() { + return thumbUrl; + } + + public void setThumbUrl(String thumbUrl) { + this.thumbUrl = thumbUrl; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getCaption() { + return caption; + } + + public void setCaption(String caption) { + this.caption = caption; + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + + jsonObject.put(TYPE_FIELD, this.type); + jsonObject.put(ID_FIELD, this.id); + jsonObject.put(PHOTOURL_FIELD, this.photoUrl); + if (parseMode != null) { + jsonObject.put(PARSEMODE_FIELD, this.parseMode); + } + if (disableWebPagePreview != null) { + jsonObject.put(DISABLEWEBPAGEPREVIEW_FIELD, this.disableWebPagePreview); + } + if (mimeType != null) { + jsonObject.put(MIMETYPE_FIELD, this.mimeType); + } + if (photoWidth != null) { + jsonObject.put(PHOTOWIDTH_FIELD, this.photoWidth); + } + if (photoHeight != null) { + jsonObject.put(PHOTOHEIGHT_FIELD, this.photoHeight); + } + if (description != null) { + jsonObject.put(DESCRIPTION_FIELD, this.description); + } + if (thumbUrl != null) { + jsonObject.put(THUMBURL_FIELD, this.thumbUrl); + } + if (title != null) { + jsonObject.put(TITLE_FIELD, this.title); + } + if (description != null) { + jsonObject.put(DESCRIPTION_FIELD, this.description); + } + if (caption != null) { + jsonObject.put(CAPTION_FIELD, this.caption); + } + if (messageText != null) { + jsonObject.put(MESSAGETEXT_FIELD, this.messageText); + } + + return jsonObject; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(TYPE_FIELD, type); + gen.writeStringField(ID_FIELD, id); + gen.writeStringField(PHOTOURL_FIELD, this.photoUrl); + if (parseMode != null) { + gen.writeStringField(PARSEMODE_FIELD, this.parseMode); + } + if (disableWebPagePreview != null) { + gen.writeBooleanField(DISABLEWEBPAGEPREVIEW_FIELD, this.disableWebPagePreview); + } + if (mimeType != null) { + gen.writeStringField(MIMETYPE_FIELD, this.mimeType); + } + if (photoWidth != null) { + gen.writeNumberField(PHOTOWIDTH_FIELD, this.photoWidth); + } + if (photoHeight != null) { + gen.writeNumberField(PHOTOHEIGHT_FIELD, this.photoHeight); + } + if (thumbUrl != null) { + gen.writeStringField(THUMBURL_FIELD, this.thumbUrl); + } + if (description != null) { + gen.writeStringField(DESCRIPTION_FIELD, this.description); + } + if (title != null) { + gen.writeStringField(TITLE_FIELD, this.title); + } + if (caption != null) { + gen.writeStringField(CAPTION_FIELD, this.caption); + } + if (messageText != null) { + gen.writeStringField(MESSAGETEXT_FIELD, this.messageText); + } + + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/InlineQueryResultVideo.java b/src/main/java/org/telegram/api/objects/InlineQueryResultVideo.java new file mode 100644 index 00000000..a946fb8e --- /dev/null +++ b/src/main/java/org/telegram/api/objects/InlineQueryResultVideo.java @@ -0,0 +1,245 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Represents link to a page containing an embedded video player or a video file. + * @date 01 of January of 2016 + */ +public class InlineQueryResultVideo implements InlineQueryResult { + + public static final String TYPE_FIELD = "type"; + @JsonProperty(TYPE_FIELD) + private final String type = "video"; ///< Type of the result, must be "video" + public static final String ID_FIELD = "id"; + @JsonProperty(ID_FIELD) + private String id; ///< Unique identifier of this result + public static final String MIMETYPE_FIELD = "mime_type"; + @JsonProperty(MIMETYPE_FIELD) + private String mimeType; ///< Mime type of the content of video url, i.e. “text/html” or “video/mp4” + public static final String VIDEOURL_FIELD = "video_url"; + @JsonProperty(VIDEOURL_FIELD) + private String videoUrl; ///< A valid URL for the embedded video player or video file + public static final String VIDEOWIDTH_FIELD = "video_width"; + @JsonProperty(VIDEOWIDTH_FIELD) + private Integer videoWidth; ///< Optional. Video width + public static final String VIDEOHEIGHT_FIELD = "video_height"; + @JsonProperty(VIDEOHEIGHT_FIELD) + private Integer videoHeight; ///< Optional. Video height + public static final String VIDEODURATION_FIELD = "video_duration"; + @JsonProperty(VIDEODURATION_FIELD) + private Integer videoDuration; ///< Optional. Video duration in seconds + public static final String THUMBURL_FIELD = "thumb_url"; + @JsonProperty(THUMBURL_FIELD) + private String thumbUrl; ///< Optional. URL of the thumbnail (jpeg only) for the video + public static final String TITLE_FIELD = "title"; + @JsonProperty(TITLE_FIELD) + private String title; ///< Optional. Title for the result + public static final String DESCRIPTION_FIELD = "description"; + @JsonProperty(DESCRIPTION_FIELD) + private String description; ///< Optional. Short description of the result + public static final String MESSAGETEXT_FIELD = "message_text"; + @JsonProperty(MESSAGETEXT_FIELD) + private String messageText; ///< Optional. Text of a message to be sent instead of the video + public static final String PARSEMODE_FIELD = "parse_mode"; + @JsonProperty(PARSEMODE_FIELD) + private String parseMode; ///< Optional. Send “Markdown”, if you want Telegram apps to show bold, italic and inline URLs in your bot's message. + public static final String DISABLEWEBPAGEPREVIEW_FIELD = "disable_web_page_preview"; + @JsonProperty(DISABLEWEBPAGEPREVIEW_FIELD) + private Boolean disableWebPagePreview; ///< Optional. Disables link previews for links in the sent message + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getMessageText() { + return messageText; + } + + public void setMessageText(String messageText) { + this.messageText = messageText; + } + + public String getParseMode() { + return parseMode; + } + + public void setParseMode(String parseMode) { + this.parseMode = parseMode; + } + + public Boolean getDisableWebPagePreview() { + return disableWebPagePreview; + } + + public void setDisableWebPagePreview(Boolean disableWebPagePreview) { + this.disableWebPagePreview = disableWebPagePreview; + } + + public String getMimeType() { + return mimeType; + } + + public void setMimeType(String mimeType) { + this.mimeType = mimeType; + } + + public String getVideoUrl() { + return videoUrl; + } + + public void setVideoUrl(String videoUrl) { + this.videoUrl = videoUrl; + } + + public Integer getVideoWidth() { + return videoWidth; + } + + public void setVideoWidth(Integer videoWidth) { + this.videoWidth = videoWidth; + } + + public Integer getVideoHeight() { + return videoHeight; + } + + public void setVideoHeight(Integer videoHeight) { + this.videoHeight = videoHeight; + } + + public Integer getVideoDuration() { + return videoDuration; + } + + public void setVideoDuration(Integer videoDuration) { + this.videoDuration = videoDuration; + } + + public String getThumbUrl() { + return thumbUrl; + } + + public void setThumbUrl(String thumbUrl) { + this.thumbUrl = thumbUrl; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + + jsonObject.put(TYPE_FIELD, this.type); + jsonObject.put(ID_FIELD, this.id); + jsonObject.put(VIDEOURL_FIELD, this.videoUrl); + if (mimeType != null) { + jsonObject.put(MIMETYPE_FIELD, this.mimeType); + } + if (messageText != null) { + jsonObject.put(MESSAGETEXT_FIELD, this.messageText); + } + if (parseMode != null) { + jsonObject.put(PARSEMODE_FIELD, this.parseMode); + } + if (disableWebPagePreview != null) { + jsonObject.put(DISABLEWEBPAGEPREVIEW_FIELD, this.disableWebPagePreview); + } + if (videoWidth != null) { + jsonObject.put(VIDEOWIDTH_FIELD, this.videoWidth); + } + if (videoHeight != null) { + jsonObject.put(VIDEOHEIGHT_FIELD, this.videoHeight); + } + if (videoDuration != null) { + jsonObject.put(VIDEODURATION_FIELD, this.videoDuration); + } + if (thumbUrl != null) { + jsonObject.put(THUMBURL_FIELD, this.thumbUrl); + } + if (title != null) { + jsonObject.put(TITLE_FIELD, this.title); + } + if (description != null) { + jsonObject.put(DESCRIPTION_FIELD, this.description); + } + + return jsonObject; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(TYPE_FIELD, type); + gen.writeStringField(ID_FIELD, id); + gen.writeStringField(VIDEOURL_FIELD, this.videoUrl); + if (mimeType != null) { + gen.writeStringField(MIMETYPE_FIELD, this.mimeType); + } + if (messageText != null) { + gen.writeStringField(MESSAGETEXT_FIELD, this.messageText); + } + if (parseMode != null) { + gen.writeStringField(PARSEMODE_FIELD, this.parseMode); + } + if (disableWebPagePreview != null) { + gen.writeBooleanField(DISABLEWEBPAGEPREVIEW_FIELD, this.disableWebPagePreview); + } + if (videoWidth != null) { + gen.writeNumberField(VIDEOWIDTH_FIELD, this.videoWidth); + } + if (videoHeight != null) { + gen.writeNumberField(VIDEOHEIGHT_FIELD, this.videoHeight); + } + if (videoDuration != null) { + gen.writeNumberField(VIDEODURATION_FIELD, this.videoDuration); + } + if (thumbUrl != null) { + gen.writeStringField(THUMBURL_FIELD, this.thumbUrl); + } + if (title != null) { + gen.writeStringField(TITLE_FIELD, this.title); + } + if (description != null) { + gen.writeStringField(DESCRIPTION_FIELD, this.description); + } + + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/Location.java b/src/main/java/org/telegram/api/objects/Location.java new file mode 100644 index 00000000..fae7c65d --- /dev/null +++ b/src/main/java/org/telegram/api/objects/Location.java @@ -0,0 +1,66 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents a point on the map. + * @date 20 of June of 2015 + */ +public class Location implements BotApiObject { + + public static final String LONGITUDE_FIELD = "longitude"; + @JsonProperty(LONGITUDE_FIELD) + private Double longitude; ///< Longitude as defined by sender + public static final String LATITUDE_FIELD = "latitude"; + @JsonProperty(LATITUDE_FIELD) + private Double latitude; ///< Latitude as defined by sender + + public Location() { + super(); + } + + public Location(JSONObject jsonObject) { + super(); + this.longitude = jsonObject.getDouble(LONGITUDE_FIELD); + this.latitude = jsonObject.getDouble(LATITUDE_FIELD); + } + + public Double getLongitude() { + return longitude; + } + + public void setLongitude(Double longitude) { + this.longitude = longitude; + } + + public Double getLatitude() { + return latitude; + } + + public void setLatitude(Double latitude) { + this.latitude = latitude; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeNumberField(LONGITUDE_FIELD, longitude); + gen.writeNumberField(LATITUDE_FIELD, latitude); + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/Message.java b/src/main/java/org/telegram/api/objects/Message.java new file mode 100644 index 00000000..7bc1af8d --- /dev/null +++ b/src/main/java/org/telegram/api/objects/Message.java @@ -0,0 +1,528 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONArray; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents a message. + * @date 20 of June of 2015 + */ +public class Message implements BotApiObject { + public static final String MESSAGEID_FIELD = "message_id"; + @JsonProperty(MESSAGEID_FIELD) + private Integer messageId; ///< Integer Unique message identifier + public static final String FROM_FIELD = "from"; + @JsonProperty(FROM_FIELD) + private User from; ///< Optional. Sender, can be empty for messages sent to channels + public static final String DATE_FIELD = "date"; + @JsonProperty(DATE_FIELD) + private Integer date; ///< Date the message was sent in Unix time + public static final String CHAT_FIELD = "chat"; + @JsonProperty(CHAT_FIELD) + private Chat chat; ///< Conversation the message belongs to + public static final String FORWARDFROM_FIELD = "forward_from"; + @JsonProperty(FORWARDFROM_FIELD) + private User forwardFrom; ///< Optional. For forwarded messages, sender of the original message + public static final String FORWARDDATE_FIELD = "forward_date"; + @JsonProperty(FORWARDDATE_FIELD) + private Integer forwardDate; ///< Optional. For forwarded messages, date the original message was sent + public static final String TEXT_FIELD = "text"; + @JsonProperty(TEXT_FIELD) + private String text; ///< Optional. For text messages, the actual UTF-8 text of the message + public static final String AUDIO_FIELD = "audio"; + @JsonProperty(AUDIO_FIELD) + private Audio audio; ///< Optional. Message is an audio file, information about the file + public static final String DOCUMENT_FIELD = "document"; + @JsonProperty(DOCUMENT_FIELD) + private Document document; ///< Optional. Message is a general file, information about the file + public static final String PHOTO_FIELD = "photo"; + @JsonProperty(PHOTO_FIELD) + private List photo; ///< Optional. Message is a photo, available sizes of the photo + public static final String STICKER_FIELD = "sticker"; + @JsonProperty(STICKER_FIELD) + private Sticker sticker; ///< Optional. Message is a sticker, information about the sticker + public static final String VIDEO_FIELD = "video"; + @JsonProperty(VIDEO_FIELD) + private Video video; ///< Optional. Message is a video, information about the video + public static final String CONTACT_FIELD = "contact"; + @JsonProperty(CONTACT_FIELD) + private Contact contact; ///< Optional. Message is a shared contact, information about the contact + public static final String LOCATION_FIELD = "location"; + @JsonProperty(LOCATION_FIELD) + private Location location; ///< Optional. Message is a shared location, information about the location + public static final String NEWCHATPARTICIPANT_FIELD = "new_chat_participant"; + @JsonProperty(NEWCHATPARTICIPANT_FIELD) + private User newChatParticipant; ///< Optional. A new member was added to the group, information about them (this member may be bot itself) + public static final String LEFTCHATPARTICIPANT_FIELD = "left_chat_participant"; + @JsonProperty(LEFTCHATPARTICIPANT_FIELD) + private User leftChatParticipant; ///< Optional. A member was removed from the group, information about them (this member may be bot itself) + public static final String NEWCHATTITLE_FIELD = "new_chat_title"; + @JsonProperty(NEWCHATTITLE_FIELD) + private String newChatTitle; ///< Optional. A chat title was changed to this value + public static final String NEWCHATPHOTO_FIELD = "new_chat_photo"; + @JsonProperty(NEWCHATPHOTO_FIELD) + private List newChatPhoto; ///< Optional. A chat photo was change to this value + public static final String DELETECHATPHOTO_FIELD = "delete_chat_photo"; + @JsonProperty(DELETECHATPHOTO_FIELD) + private Boolean deleteChatPhoto; ///< Optional. Informs that the chat photo was deleted + public static final String GROUPCHATCREATED_FIELD = "group_chat_created"; + @JsonProperty(GROUPCHATCREATED_FIELD) + private Boolean groupchatCreated; ///< Optional. Informs that the group has been created + public static final String REPLYTOMESSAGE_FIELD = "reply_to_message"; + @JsonProperty(REPLYTOMESSAGE_FIELD) + private Message replyToMessage; + public static final String VOICE_FIELD = "voice"; + @JsonProperty(VOICE_FIELD) + private Voice voice; ///< Optional. Message is a voice message, information about the file + public static final String SUPERGROUPCREATED_FIELD = "supergroup_chat_created"; + @JsonProperty(SUPERGROUPCREATED_FIELD) + private Boolean superGroupCreated; ///< Optional. Informs that the supergroup has been created + public static final String CHANNELCHATCREATED_FIELD = "channel_chat_created"; + @JsonProperty(CHANNELCHATCREATED_FIELD) + private Boolean channelChatCreated; ///< Optional. Informs that the channel has been created + public static final String MIGRATETOCHAT_FIELD = "migrate_to_chat_id"; + @JsonProperty(MIGRATETOCHAT_FIELD) + private Long migrateToChatId; ///< Optional. The chat has been migrated to a chat with specified identifier, not exceeding 1e13 by absolute value + public static final String MIGRATEFROMCHAT_FIELD = "migrate_from_chat_id"; + @JsonProperty(MIGRATEFROMCHAT_FIELD) + private Long migrateFromChatId; ///< Optional. The chat has been migrated from a chat with specified identifier, not exceeding 1e13 by absolute value + + public Message() { + super(); + } + + public Message(JSONObject jsonObject) { + super(); + this.messageId = jsonObject.getInt(MESSAGEID_FIELD); + if (jsonObject.has(FROM_FIELD)) { + this.from = new User(jsonObject.getJSONObject(FROM_FIELD)); + } + this.date = jsonObject.getInt(DATE_FIELD); + this.chat = new Chat(jsonObject.getJSONObject(CHAT_FIELD)); + if (jsonObject.has(FORWARDFROM_FIELD)) { + this.forwardFrom = new User(jsonObject.getJSONObject(FORWARDFROM_FIELD)); + } + if (jsonObject.has(FORWARDDATE_FIELD)) { + this.forwardDate = jsonObject.getInt(FORWARDDATE_FIELD); + } + if (jsonObject.has(TEXT_FIELD)) { + this.text = jsonObject.getString(TEXT_FIELD); + } + if (jsonObject.has(AUDIO_FIELD)) { + this.audio = new Audio(jsonObject.getJSONObject(AUDIO_FIELD)); + } + if (jsonObject.has(DOCUMENT_FIELD)) { + this.document = new Document(jsonObject.getJSONObject(DOCUMENT_FIELD)); + } + if (jsonObject.has(PHOTO_FIELD)) { + this.photo = new ArrayList<>(); + JSONArray photos = jsonObject.getJSONArray(PHOTO_FIELD); + for (int i = 0; i < photos.length(); i++) { + this.photo.add(new PhotoSize(photos.getJSONObject(i))); + } + } + if (jsonObject.has(STICKER_FIELD)) { + this.sticker = new Sticker(jsonObject.getJSONObject(STICKER_FIELD)); + } + if (jsonObject.has(VIDEO_FIELD)) { + this.video = new Video(jsonObject.getJSONObject(VIDEO_FIELD)); + } + if (jsonObject.has(CONTACT_FIELD)) { + this.contact = new Contact(jsonObject.getJSONObject(CONTACT_FIELD)); + } + if (jsonObject.has(LOCATION_FIELD)) { + this.location = new Location(jsonObject.getJSONObject(LOCATION_FIELD)); + } + if (jsonObject.has(VOICE_FIELD)) { + this.voice = new Voice(jsonObject.getJSONObject(VOICE_FIELD)); + } + if (jsonObject.has(NEWCHATPARTICIPANT_FIELD)) { + this.newChatParticipant = new User(jsonObject.getJSONObject(NEWCHATPARTICIPANT_FIELD)); + } + if (jsonObject.has(LEFTCHATPARTICIPANT_FIELD)) { + this.leftChatParticipant = new User(jsonObject.getJSONObject(LEFTCHATPARTICIPANT_FIELD)); + } + if (jsonObject.has(REPLYTOMESSAGE_FIELD)) { + this.replyToMessage = new Message(jsonObject.getJSONObject(REPLYTOMESSAGE_FIELD)); + } + if (jsonObject.has(NEWCHATTITLE_FIELD)) { + this.newChatTitle = jsonObject.getString(NEWCHATTITLE_FIELD); + } + if (jsonObject.has(NEWCHATPHOTO_FIELD)) { + JSONArray photoArray = jsonObject.getJSONArray(NEWCHATPHOTO_FIELD); + this.newChatPhoto = new ArrayList<>(); + for (int i = 0; i < photoArray.length(); i++) { + this.newChatPhoto.add(new PhotoSize(photoArray.getJSONObject(i))); + } + } + if (jsonObject.has(DELETECHATPHOTO_FIELD)) { + this.deleteChatPhoto = true; + } + if (jsonObject.has(GROUPCHATCREATED_FIELD)) { + this.groupchatCreated = true; + } + if (jsonObject.has(SUPERGROUPCREATED_FIELD)) { + this.superGroupCreated = true; + } + if (jsonObject.has(CHANNELCHATCREATED_FIELD)) { + this.channelChatCreated = true; + } + if (jsonObject.has(MIGRATETOCHAT_FIELD)) { + this.migrateToChatId = jsonObject.getLong(MIGRATETOCHAT_FIELD); + } + if (jsonObject.has(MIGRATEFROMCHAT_FIELD)) { + this.migrateFromChatId = jsonObject.getLong(MIGRATEFROMCHAT_FIELD); + } + } + + public Integer getMessageId() { + return messageId; + } + + public void setMessageId(Integer messageId) { + this.messageId = messageId; + } + + public User getFrom() { + return from; + } + + public void setFrom(User from) { + this.from = from; + } + + public Integer getDate() { + return date; + } + + public void setDate(Integer date) { + this.date = date; + } + + public boolean isGroupMessage() { + return chat.isGroupChat(); + } + + public boolean isUserMessage() { + return chat.isUserChat(); + } + + public boolean isChannelMessage() { + return chat.isChannelChat(); + } + + public boolean isSuperGroupMessage() { + return chat.isSuperGroupChat(); + } + + public Long getChatId() { + return chat.getId(); + } + + public Chat getChat() { + return chat; + } + + public void setChat(Chat chat) { + this.chat = chat; + } + + public User getForwardFrom() { + return forwardFrom; + } + + public void setForwardFrom(User forwardFrom) { + this.forwardFrom = forwardFrom; + } + + public Integer getForwardDate() { + return forwardDate; + } + + public void setForwardDate(Integer forwardDate) { + this.forwardDate = forwardDate; + } + + public boolean hasText() { + return text != null && !text.isEmpty(); + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public Audio getAudio() { + return audio; + } + + public void setAudio(Audio audio) { + this.audio = audio; + } + + public boolean hasDocument() { + return this.document != null; + } + + public Document getDocument() { + return document; + } + + public void setDocument(Document document) { + this.document = document; + } + + public List getPhoto() { + return photo; + } + + public void setPhoto(List photo) { + this.photo = photo; + } + + public Sticker getSticker() { + return sticker; + } + + public void setSticker(Sticker sticker) { + this.sticker = sticker; + } + + public Video getVideo() { + return video; + } + + public void setVideo(Video video) { + this.video = video; + } + + public Contact getContact() { + return contact; + } + + public void setContact(Contact contact) { + this.contact = contact; + } + + public Location getLocation() { + return location; + } + + public void setLocation(Location location) { + this.location = location; + } + + public User getNewChatParticipant() { + return newChatParticipant; + } + + public void setNewChatParticipant(User newChatParticipant) { + this.newChatParticipant = newChatParticipant; + } + + public User getLeftChatParticipant() { + return leftChatParticipant; + } + + public void setLeftChatParticipant(User leftChatParticipant) { + this.leftChatParticipant = leftChatParticipant; + } + + public String getNewChatTitle() { + return newChatTitle; + } + + public void setNewChatTitle(String newChatTitle) { + this.newChatTitle = newChatTitle; + } + + public List getNewChatPhoto() { + return newChatPhoto; + } + + public void setNewChatPhoto(List newChatPhoto) { + this.newChatPhoto = newChatPhoto; + } + + public Boolean getDeleteChatPhoto() { + return deleteChatPhoto; + } + + public void setDeleteChatPhoto(Boolean deleteChatPhoto) { + this.deleteChatPhoto = deleteChatPhoto; + } + + public Boolean getGroupchatCreated() { + return groupchatCreated; + } + + public void setGroupchatCreated(Boolean groupchatCreated) { + this.groupchatCreated = groupchatCreated; + } + + public boolean hasReplayMessage() { + return replyToMessage != null; + } + + public Message getReplyToMessage() { + return replyToMessage; + } + + public void setReplyToMessage(Message replyToMessage) { + this.replyToMessage = replyToMessage; + } + + public boolean isReply() { + return this.replyToMessage != null; + } + + public boolean hasLocation() { + return location != null; + } + + public Voice getVoice() { + return voice; + } + + public void setVoice(Voice voice) { + this.voice = voice; + } + + public Boolean getSuperGroupCreated() { + return superGroupCreated; + } + + public void setSuperGroupCreated(Boolean superGroupCreated) { + this.superGroupCreated = superGroupCreated; + } + + public Boolean getChannelChatCreated() { + return channelChatCreated; + } + + public void setChannelChatCreated(Boolean channelChatCreated) { + this.channelChatCreated = channelChatCreated; + } + + public Long getMigrateToChatId() { + return migrateToChatId; + } + + public void setMigrateToChatId(Long migrateToChatId) { + this.migrateToChatId = migrateToChatId; + } + + public Long getMigrateFromChatId() { + return migrateFromChatId; + } + + public void setMigrateFromChatId(Long migrateFromChatId) { + this.migrateFromChatId = migrateFromChatId; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + + gen.writeNumberField(MESSAGEID_FIELD, messageId); + gen.writeObjectField(FROM_FIELD, from); + gen.writeNumberField(DATE_FIELD, date); + gen.writeObjectField(CHAT_FIELD, chat); + + if (forwardFrom != null) { + gen.writeObjectField(FORWARDFROM_FIELD, forwardFrom); + } + if (forwardDate != null) { + gen.writeNumberField(FORWARDDATE_FIELD, forwardDate); + } + if (text != null) { + gen.writeStringField(TEXT_FIELD, text); + } + if (audio != null) { + gen.writeObjectField(AUDIO_FIELD, audio); + } + if (document != null) { + gen.writeObjectField(DOCUMENT_FIELD, document); + } + if (photo != null && photo.size() > 0) { + gen.writeArrayFieldStart(PHOTO_FIELD); + for (PhotoSize photoSize : photo) { + gen.writeObject(photoSize); + } + gen.writeEndArray(); + } + if (sticker != null) { + gen.writeObjectField(STICKER_FIELD, sticker); + } + if (video != null) { + gen.writeObjectField(VIDEO_FIELD, video); + } + if (contact != null) { + gen.writeObjectField(CONTACT_FIELD, contact); + } + if (location != null) { + gen.writeObjectField(LOCATION_FIELD, location); + } + if (voice != null) { + gen.writeObjectField(VOICE_FIELD, voice); + } + if (newChatParticipant != null) { + gen.writeObjectField(NEWCHATPARTICIPANT_FIELD, newChatParticipant); + } + if (leftChatParticipant != null) { + gen.writeObjectField(LEFTCHATPARTICIPANT_FIELD, leftChatParticipant); + } + if (replyToMessage != null) { + gen.writeObjectField(REPLYTOMESSAGE_FIELD, replyToMessage); + } + if (newChatTitle != null) { + gen.writeStringField(NEWCHATTITLE_FIELD, newChatTitle); + } + if (newChatPhoto != null && newChatPhoto.size() > 0) { + gen.writeArrayFieldStart(NEWCHATPHOTO_FIELD); + for (PhotoSize photoSize: newChatPhoto) { + gen.writeObject(photoSize); + } + gen.writeEndArray(); + } + if (deleteChatPhoto != null) { + gen.writeBooleanField(DELETECHATPHOTO_FIELD, deleteChatPhoto); + } + if (groupchatCreated != null) { + gen.writeBooleanField(GROUPCHATCREATED_FIELD, groupchatCreated); + } + if (superGroupCreated != null) { + gen.writeBooleanField(SUPERGROUPCREATED_FIELD, superGroupCreated); + } + if (channelChatCreated != null) { + gen.writeBooleanField(CHANNELCHATCREATED_FIELD, channelChatCreated); + } + if (migrateToChatId != null) { + gen.writeNumberField(MIGRATETOCHAT_FIELD, migrateToChatId); + } + if (migrateFromChatId != null) { + gen.writeNumberField(MIGRATEFROMCHAT_FIELD, migrateFromChatId); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/PhotoSize.java b/src/main/java/org/telegram/api/objects/PhotoSize.java new file mode 100644 index 00000000..5ade74dc --- /dev/null +++ b/src/main/java/org/telegram/api/objects/PhotoSize.java @@ -0,0 +1,96 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents one size of a photo or a file / sticker thumbnail. + * @date 20 of June of 2015 + */ +public class PhotoSize implements BotApiObject { + + public static final String FILEID_FIELD = "file_id"; + @JsonProperty(FILEID_FIELD) + private String fileId; ///< Unique identifier for this file + public static final String WIDTH_FIELD = "width"; + @JsonProperty(WIDTH_FIELD) + private Integer width; ///< Photo width + public static final String HEIGHT_FIELD = "height"; + @JsonProperty(HEIGHT_FIELD) + private Integer height; ///< Photo height + public static final String FILESIZE_FIELD = "file_size"; + @JsonProperty(FILESIZE_FIELD) + private Integer fileSize; ///< Optional. File size + + public PhotoSize() { + super(); + } + + public PhotoSize(JSONObject jsonObject) { + super(); + this.fileId = jsonObject.getString(FILEID_FIELD); + this.width = jsonObject.getInt(WIDTH_FIELD); + this.height = jsonObject.getInt(HEIGHT_FIELD); + if (jsonObject.has(FILESIZE_FIELD)) { + this.fileSize = jsonObject.getInt(FILESIZE_FIELD); + } + } + + public String getFileId() { + return fileId; + } + + public void setFileId(String fileId) { + this.fileId = fileId; + } + + public Integer getWidth() { + return width; + } + + public void setWidth(Integer width) { + this.width = width; + } + + public Integer getHeight() { + return height; + } + + public void setHeight(Integer height) { + this.height = height; + } + + public Integer getFileSize() { + return fileSize; + } + + public void setFileSize(Integer fileSize) { + this.fileSize = fileSize; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(FILEID_FIELD, fileId); + gen.writeNumberField(WIDTH_FIELD, width); + gen.writeNumberField(HEIGHT_FIELD, height); + if (fileSize != null) { + gen.writeNumberField(FILESIZE_FIELD, fileSize); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/ReplyKeyboard.java b/src/main/java/org/telegram/api/objects/ReplyKeyboard.java new file mode 100644 index 00000000..3e742a2f --- /dev/null +++ b/src/main/java/org/telegram/api/objects/ReplyKeyboard.java @@ -0,0 +1,13 @@ +package org.telegram.api.objects; + +import org.telegram.api.interfaces.BotApiObject; +import org.telegram.api.interfaces.IToJson; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Reply keyboard abstract type + * @date 20 of June of 2015 + */ +public interface ReplyKeyboard extends BotApiObject, IToJson { +} diff --git a/src/main/java/org/telegram/api/objects/ReplyKeyboardHide.java b/src/main/java/org/telegram/api/objects/ReplyKeyboardHide.java new file mode 100644 index 00000000..c6527a6b --- /dev/null +++ b/src/main/java/org/telegram/api/objects/ReplyKeyboardHide.java @@ -0,0 +1,88 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Upon receiving a message with this object, + * Telegram clients will hide the current custom keyboard and display the default letter-keyboard. + * By default, custom keyboards are displayed until a new keyboard is sent by a bot. + * An exception is made for one-time keyboards that are hidden immediately after the user presses a button + * (@see ReplyKeyboardMarkup). + * @date 20 of June of 2015 + */ +public class ReplyKeyboardHide implements ReplyKeyboard { + + public static final String HIDEKEYBOARD_FIELD = "hide_keyboard"; + @JsonProperty(HIDEKEYBOARD_FIELD) + private Boolean hideKeyboard; ///< Requests clients to hide the custom keyboard + public static final String SELECTIVE_FIELD = "selective"; + /** + * Optional. Use this parameter if you want to show the keyboard to specific users only. + * Targets: + * 1) users that are @mentioned in the text of the Message object; + * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. + */ + @JsonProperty(SELECTIVE_FIELD) + private Boolean selective; + + public ReplyKeyboardHide() { + super(); + this.selective = true; + } + + public ReplyKeyboardHide(JSONObject jsonObject) { + super(); + if (jsonObject.has(HIDEKEYBOARD_FIELD)) { + this.hideKeyboard = jsonObject.getBoolean(HIDEKEYBOARD_FIELD); + } + if (jsonObject.has(SELECTIVE_FIELD)) { + this.selective = jsonObject.getBoolean(SELECTIVE_FIELD); + } + } + + public Boolean getHideKeyboard() { + return hideKeyboard; + } + + public void setHideKeyboard(Boolean hideKeyboard) { + this.hideKeyboard = hideKeyboard; + } + + public Boolean getSelective() { + return selective; + } + + public void setSelective(Boolean selective) { + this.selective = selective; + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + jsonObject.put(HIDEKEYBOARD_FIELD, this.hideKeyboard); + jsonObject.put(SELECTIVE_FIELD, this.selective); + return jsonObject; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeBooleanField(HIDEKEYBOARD_FIELD, hideKeyboard); + gen.writeBooleanField(SELECTIVE_FIELD, selective); + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/ReplyKeyboardMarkup.java b/src/main/java/org/telegram/api/objects/ReplyKeyboardMarkup.java new file mode 100644 index 00000000..c320af33 --- /dev/null +++ b/src/main/java/org/telegram/api/objects/ReplyKeyboardMarkup.java @@ -0,0 +1,156 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONArray; +import org.json.JSONObject; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents a custom keyboard with reply options. + * @date 20 of June of 2015 + */ +public class ReplyKeyboardMarkup implements ReplyKeyboard { + + public static final String KEYBOARD_FIELD = "keyboard"; + @JsonProperty(KEYBOARD_FIELD) + private List> keyboard; ///< Array of button rows, each represented by an Array of Strings + public static final String RESIZEKEYBOARD_FIELD = "resize_keyboard"; + @JsonProperty(RESIZEKEYBOARD_FIELD) + private Boolean resizeKeyboard; ///< Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false. + public static final String ONETIMEKEYBOARD_FIELD = "one_time_keyboard"; + @JsonProperty(ONETIMEKEYBOARD_FIELD) + private Boolean oneTimeKeyboad; ///< Optional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false. + public static final String SELECTIVE_FIELD = "selective"; + /** + * Optional. Use this parameter if you want to show the keyboard to specific users only. + * Targets: + * 1) users that are @mentioned in the text of the Message object; + * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. + */ + private Boolean selective; + + public ReplyKeyboardMarkup() { + super(); + keyboard = new ArrayList>(); + } + + public ReplyKeyboardMarkup(JSONObject jsonObject) { + super(); + this.keyboard = new ArrayList>(); + JSONArray keyboard = jsonObject.getJSONArray(KEYBOARD_FIELD); + for (int i=0; i< keyboard.length(); i++) { + JSONArray keyboardRow = keyboard.getJSONArray(i); + List row = new ArrayList(); + for (int j=0; j < keyboardRow.length(); j++) { + row.add(keyboardRow.getString(j)); + } + this.keyboard.add(row); + } + if (jsonObject.has(RESIZEKEYBOARD_FIELD)) { + this.resizeKeyboard = jsonObject.getBoolean(RESIZEKEYBOARD_FIELD); + } + if (jsonObject.has(ONETIMEKEYBOARD_FIELD)) { + this.oneTimeKeyboad = jsonObject.getBoolean(ONETIMEKEYBOARD_FIELD); + } + if (jsonObject.has(SELECTIVE_FIELD)) { + this.selective = jsonObject.getBoolean(SELECTIVE_FIELD); + } + } + + public List> getKeyboard() { + return keyboard; + } + + public void setKeyboard(List> keyboard) { + this.keyboard = keyboard; + } + + public Boolean getResizeKeyboard() { + return resizeKeyboard; + } + + public void setResizeKeyboard(Boolean resizeKeyboard) { + this.resizeKeyboard = resizeKeyboard; + } + + public Boolean getOneTimeKeyboad() { + return oneTimeKeyboad; + } + + public void setOneTimeKeyboad(Boolean oneTimeKeyboad) { + this.oneTimeKeyboad = oneTimeKeyboad; + } + + public Boolean getSelective() { + return selective; + } + + public void setSelective(Boolean selective) { + this.selective = selective; + } + + @Override + public JSONObject toJson() { + JSONObject jsonObject = new JSONObject(); + JSONArray jsonkeyboard = new JSONArray(); + + for (List innerRow : this.keyboard) { + JSONArray innerJSONKeyboard = new JSONArray(); + for (String element: innerRow) { + innerJSONKeyboard.put(element); + } + jsonkeyboard.put(innerJSONKeyboard); + } + jsonObject.put(ReplyKeyboardMarkup.KEYBOARD_FIELD, jsonkeyboard); + + if (this.oneTimeKeyboad != null) { + jsonObject.put(ReplyKeyboardMarkup.ONETIMEKEYBOARD_FIELD, this.oneTimeKeyboad); + } + if (this.resizeKeyboard != null) { + jsonObject.put(ReplyKeyboardMarkup.RESIZEKEYBOARD_FIELD, this.resizeKeyboard); + } + if (this.selective != null) { + jsonObject.put(ReplyKeyboardMarkup.SELECTIVE_FIELD, this.selective); + } + + return jsonObject; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeArrayFieldStart(KEYBOARD_FIELD); + for (List innerRow : keyboard) { + gen.writeStartArray(); + for (String element: innerRow) { + gen.writeString(element); + } + gen.writeEndArray(); + } + gen.writeEndArray(); + if (this.oneTimeKeyboad != null) { + gen.writeBooleanField(ONETIMEKEYBOARD_FIELD, oneTimeKeyboad); + } + if (this.resizeKeyboard != null) { + gen.writeBooleanField(RESIZEKEYBOARD_FIELD, resizeKeyboard); + } + if (this.selective != null) { + gen.writeBooleanField(SELECTIVE_FIELD, selective); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/Sticker.java b/src/main/java/org/telegram/api/objects/Sticker.java new file mode 100644 index 00000000..d9c700ff --- /dev/null +++ b/src/main/java/org/telegram/api/objects/Sticker.java @@ -0,0 +1,73 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents a sticker. + * @date 20 of June of 2015 + */ +public class Sticker implements BotApiObject { + + public static final String FILEID_FIELD = "file_id"; + @JsonProperty(FILEID_FIELD) + private String fileId; ///< Unique identifier for this file + public static final String WIDTH_FIELD = "width"; + @JsonProperty(WIDTH_FIELD) + private Integer width; ///< Sticker width + public static final String HEIGHT_FIELD = "height"; + @JsonProperty(HEIGHT_FIELD) + private Integer height; ///< Sticker height + public static final String THUMB_FIELD = "thumb"; + @JsonProperty(THUMB_FIELD) + private PhotoSize thumb; ///< Optional. Sticker thumbnail in .webp or .jpg format + public static final String FILESIZE_FIELD = "file_size"; + @JsonProperty(FILESIZE_FIELD) + private Integer fileSize; ///< Optional. File size + + public Sticker() { + super(); + } + + public Sticker(JSONObject jsonObject) { + super(); + this.fileId = jsonObject.getString(FILEID_FIELD); + this.width = jsonObject.getInt(WIDTH_FIELD); + this.height = jsonObject.getInt(HEIGHT_FIELD); + if (jsonObject.has(THUMB_FIELD)) { + this.thumb = new PhotoSize(jsonObject.getJSONObject(THUMB_FIELD)); + } + if (jsonObject.has(FILESIZE_FIELD)) { + this.fileSize = jsonObject.getInt(FILESIZE_FIELD); + } + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(FILEID_FIELD, fileId); + gen.writeNumberField(WIDTH_FIELD, width); + gen.writeNumberField(HEIGHT_FIELD, height); + if (thumb != null) { + gen.writeObjectField(THUMB_FIELD, thumb); + } + if (fileSize != null) { + gen.writeNumberField(FILESIZE_FIELD, fileSize); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/Update.java b/src/main/java/org/telegram/api/objects/Update.java new file mode 100644 index 00000000..26c7d09e --- /dev/null +++ b/src/main/java/org/telegram/api/objects/Update.java @@ -0,0 +1,104 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents an incoming update. + * Only one of the optional parameters can be present in any given update. + * @date 20 of June of 2015 + */ +public class Update implements BotApiObject { + public static final String UPDATEID_FIELD = "update_id"; + @JsonProperty(UPDATEID_FIELD) + private Integer updateId; + public static final String MESSAGE_FIELD = "message"; + @JsonProperty(MESSAGE_FIELD) + private Message message; ///< Optional. New incoming message of any kind — text, photo, sticker, etc. + public static final String INLINEQUERY_FIELD = "inline_query"; + @JsonProperty(INLINEQUERY_FIELD) + private InlineQuery inlineQuery; ///< Optional. New incoming inline query + public static final String CHOSENINLINEQUERY_FIELD = "chosen_inline_result"; + @JsonProperty(CHOSENINLINEQUERY_FIELD) + private ChosenInlineQuery chosenInlineQuery; ///< Optional. The result of a inline query that was chosen by a user and sent to their chat partner + + /* + ChosenInlineResult + */ + + public Update() { + super(); + } + + public Update(JSONObject jsonObject) { + super(); + this.updateId = jsonObject.getInt(UPDATEID_FIELD); + if (jsonObject.has(MESSAGE_FIELD)) { + this.message = new Message(jsonObject.getJSONObject(MESSAGE_FIELD)); + } + if (jsonObject.has(INLINEQUERY_FIELD)) { + this.inlineQuery = new InlineQuery(jsonObject.getJSONObject(INLINEQUERY_FIELD)); + } + if (jsonObject.has(CHOSENINLINEQUERY_FIELD)) { + this.chosenInlineQuery = new ChosenInlineQuery(jsonObject.getJSONObject(CHOSENINLINEQUERY_FIELD)); + } + } + + public Integer getUpdateId() { + return updateId; + } + + public Message getMessage() { + return message; + } + + public InlineQuery getInlineQuery() { + return inlineQuery; + } + + public ChosenInlineQuery getChosenInlineQuery() { + return chosenInlineQuery; + } + + public boolean hasMessage() { + return message != null; + } + + public boolean hasInlineQuery() { + return inlineQuery != null; + } + + public boolean hasChosenInlineQuery() { + return chosenInlineQuery != null; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeNumberField(UPDATEID_FIELD, updateId); + if (message != null) { + gen.writeObjectField(MESSAGE_FIELD, message); + } + if (inlineQuery != null) { + gen.writeObjectField(INLINEQUERY_FIELD, inlineQuery); + } + if (chosenInlineQuery != null) { + gen.writeObjectField(CHOSENINLINEQUERY_FIELD, chosenInlineQuery); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/User.java b/src/main/java/org/telegram/api/objects/User.java new file mode 100644 index 00000000..5ccaf22e --- /dev/null +++ b/src/main/java/org/telegram/api/objects/User.java @@ -0,0 +1,84 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents a Telegram user or bot. + * @date 20 of June of 2015 + */ +public class User implements BotApiObject { + + public static final String ID_FIELD = "id"; + @JsonProperty(ID_FIELD) + private Integer id; ///< Unique identifier for this user or bot + public static final String FIRSTNAME_FIELD = "first_name"; + @JsonProperty(FIRSTNAME_FIELD) + private String firstName; ///< User‘s or bot’s first name + public static final String LASTNAME_FIELD = "last_name"; + @JsonProperty(LASTNAME_FIELD) + private String lastName; ///< Optional. User‘s or bot’s last name + public static final String USERNAME_FIELD = "username"; + @JsonProperty(USERNAME_FIELD) + private String userName; ///< Optional. User‘s or bot’s username + + public User() { + super(); + } + + public User(JSONObject jsonObject) { + super(); + this.id = jsonObject.getInt(ID_FIELD); + this.firstName = jsonObject.getString(FIRSTNAME_FIELD); + if (jsonObject.has(LASTNAME_FIELD)) { + this.lastName = jsonObject.getString(LASTNAME_FIELD); + } + if (jsonObject.has(USERNAME_FIELD)) { + this.userName = jsonObject.getString(USERNAME_FIELD); + } + } + + public Integer getId() { + return id; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public String getUserName() { + return userName; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeNumberField(ID_FIELD, id); + gen.writeStringField(FIRSTNAME_FIELD, firstName); + if (lastName != null) { + gen.writeStringField(LASTNAME_FIELD, lastName); + } + if (userName != null) { + gen.writeStringField(USERNAME_FIELD, userName); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/UserProfilePhotos.java b/src/main/java/org/telegram/api/objects/UserProfilePhotos.java new file mode 100644 index 00000000..23ace481 --- /dev/null +++ b/src/main/java/org/telegram/api/objects/UserProfilePhotos.java @@ -0,0 +1,90 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONArray; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represent a user's profile pictures. + * @date 22 of June of 2015 + */ +public class UserProfilePhotos implements BotApiObject { + + public static final String TOTALCOUNT_FIELD = "total_count"; + @JsonProperty(TOTALCOUNT_FIELD) + private Integer totalCount; ///< Total number of profile pictures the target user has + public static final String PHOTOS_FIELD = "photos"; + @JsonProperty(PHOTOS_FIELD) + private List> photos; ///< Requested profile pictures (in up to 4 sizes each) + + public UserProfilePhotos() { + super(); + } + + public UserProfilePhotos(JSONObject jsonObject) { + super(); + this.totalCount = jsonObject.getInt(TOTALCOUNT_FIELD); + if (totalCount > 0) { + this.photos = new ArrayList<>(); + JSONArray photos = jsonObject.getJSONArray(PHOTOS_FIELD); + for (int i = 0; i < photos.length(); i++) { + JSONArray innerArray = photos.getJSONArray(i); + List innerPhotos = new ArrayList<>(); + for (int j = 0; j < innerArray.length(); j++) { + innerPhotos.add(new PhotoSize(innerArray.getJSONObject(j))); + } + this.photos.add(innerPhotos); + } + } + } + + public Integer getTotalCount() { + return totalCount; + } + + public void setTotalCount(Integer totalCount) { + this.totalCount = totalCount; + } + + public List> getPhotos() { + return photos; + } + + public void setPhotos(List> photos) { + this.photos = photos; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeNumberField(TOTALCOUNT_FIELD, totalCount); + if (totalCount > 0) { + gen.writeArrayFieldStart(PHOTOS_FIELD); + for (List photoSizeList : photos) { + gen.writeStartArray(); + for (PhotoSize photoSize: photoSizeList) { + gen.writeObject(photoSize); + } + gen.writeEndArray(); + } + gen.writeEndArray(); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/Video.java b/src/main/java/org/telegram/api/objects/Video.java new file mode 100644 index 00000000..b5be814d --- /dev/null +++ b/src/main/java/org/telegram/api/objects/Video.java @@ -0,0 +1,142 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents a video file. + * @date 20 of June of 2015 + */ +public class Video implements BotApiObject { + + public static final String FILEID_FIELD = "file_id"; + @JsonProperty(FILEID_FIELD) + private String fileId; ///< Unique identifier for this file + public static final String WIDTH_FIELD = "width"; + @JsonProperty(WIDTH_FIELD) + private Integer width; ///< Video width as defined by sender + public static final String HEIGHT_FIELD = "height"; + @JsonProperty(HEIGHT_FIELD) + private Integer height; ///< Video height as defined by sender + public static final String DURATION_FIELD = "duration"; + @JsonProperty(DURATION_FIELD) + private Integer duration; ///< Duration of the video in seconds as defined by sender + public static final String THUMB_FIELD = "thumb"; + @JsonProperty(THUMB_FIELD) + private PhotoSize thumb; ///< Video thumbnail + public static final String MIMETYPE_FIELD = "mime_type"; + @JsonProperty(MIMETYPE_FIELD) + private String mimeType; ///< Optional. Mime type of a file as defined by sender + public static final String FILESIZE_FIELD = "file_size"; + @JsonProperty(FILESIZE_FIELD) + private Integer fileSize; ///< Optional. File size + + public Video() { + super(); + } + + public Video(JSONObject jsonObject) { + this.fileId = jsonObject.getString(FILEID_FIELD); + this.width = jsonObject.getInt(WIDTH_FIELD); + this.height = jsonObject.getInt(HEIGHT_FIELD); + this.duration = jsonObject.getInt(DURATION_FIELD); + if (jsonObject.has(THUMB_FIELD)) { + this.thumb = new PhotoSize(jsonObject.getJSONObject(THUMB_FIELD)); + } + if (jsonObject.has(MIMETYPE_FIELD)) { + this.mimeType = jsonObject.getString(MIMETYPE_FIELD); + } + if (jsonObject.has(FILESIZE_FIELD)) { + this.fileSize = jsonObject.getInt(FILESIZE_FIELD); + } + } + + public Integer getWidth() { + return width; + } + + public void setWidth(Integer width) { + this.width = width; + } + + public String getFileId() { + return fileId; + } + + public void setFileId(String fileId) { + this.fileId = fileId; + } + + public Integer getHeight() { + return height; + } + + public void setHeight(Integer height) { + this.height = height; + } + + public Integer getDuration() { + return duration; + } + + public void setDuration(Integer duration) { + this.duration = duration; + } + + public PhotoSize getThumb() { + return thumb; + } + + public void setThumb(PhotoSize thumb) { + this.thumb = thumb; + } + + public String getMimeType() { + return mimeType; + } + + public void setMimeType(String mimeType) { + this.mimeType = mimeType; + } + + public Integer getFileSize() { + return fileSize; + } + + public void setFileSize(Integer fileSize) { + this.fileSize = fileSize; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(FILEID_FIELD, fileId); + gen.writeNumberField(WIDTH_FIELD, width); + gen.writeNumberField(HEIGHT_FIELD, height); + gen.writeNumberField(DURATION_FIELD, duration); + if (thumb != null) { + gen.writeObjectField(THUMB_FIELD, thumb); + } + if (mimeType != null) { + gen.writeStringField(MIMETYPE_FIELD, mimeType); + } + if (fileSize != null) { + gen.writeNumberField(FILESIZE_FIELD, fileSize); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/api/objects/Voice.java b/src/main/java/org/telegram/api/objects/Voice.java new file mode 100644 index 00000000..06fc9fba --- /dev/null +++ b/src/main/java/org/telegram/api/objects/Voice.java @@ -0,0 +1,99 @@ +package org.telegram.api.objects; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import org.json.JSONObject; +import org.telegram.api.interfaces.BotApiObject; + +import java.io.IOException; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief This object represents a voice note + * @date 16 of July of 2015 + */ +public class Voice implements BotApiObject { + public static final String FILEID_FIELD = "file_id"; + @JsonProperty(FILEID_FIELD) + private String fileId; ///< Unique identifier for this file + public static final String DURATION_FIELD = "duration"; + @JsonProperty(DURATION_FIELD) + private Integer duration; ///< Integer Duration of the audio in seconds as defined by sender + public static final String MIMETYPE_FIELD = "mime_type"; + @JsonProperty(MIMETYPE_FIELD) + private String mimeType; ///< Optional. MIME type of the file as defined by sender + public static final String FILESIZE_FIELD = "file_size"; + @JsonProperty(FILESIZE_FIELD) + private Integer fileSize; ///< Optional. File size + + public Voice() { + super(); + } + + public Voice(JSONObject jsonObject) { + super(); + this.fileId = jsonObject.getString(FILEID_FIELD); + this.duration = jsonObject.getInt(DURATION_FIELD); + if (jsonObject.has(MIMETYPE_FIELD)) { + this.mimeType = jsonObject.getString(MIMETYPE_FIELD); + } + if (jsonObject.has(FILESIZE_FIELD)) { + this.fileSize = jsonObject.getInt(FILESIZE_FIELD); + } + } + + public String getFileId() { + return fileId; + } + + public void setFileId(String fileId) { + this.fileId = fileId; + } + + public Integer getDuration() { + return duration; + } + + public void setDuration(Integer duration) { + this.duration = duration; + } + + public String getMimeType() { + return mimeType; + } + + public void setMimeType(String mimeType) { + this.mimeType = mimeType; + } + + public Integer getFileSize() { + return fileSize; + } + + public void setFileSize(Integer fileSize) { + this.fileSize = fileSize; + } + + @Override + public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeStartObject(); + gen.writeStringField(FILEID_FIELD, fileId); + gen.writeNumberField(DURATION_FIELD, duration); + if (mimeType != null) { + gen.writeStringField(MIMETYPE_FIELD, mimeType); + } + if (fileSize != null) { + gen.writeNumberField(FILESIZE_FIELD, fileSize); + } + gen.writeEndObject(); + gen.flush(); + } + + @Override + public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { + serialize(gen, serializers); + } +} diff --git a/src/main/java/org/telegram/services/BotLogger.java b/src/main/java/org/telegram/services/BotLogger.java new file mode 100644 index 00000000..fd180b9c --- /dev/null +++ b/src/main/java/org/telegram/services/BotLogger.java @@ -0,0 +1,348 @@ +package org.telegram.services; + +import org.telegram.BuildVars; + +import javax.validation.constraints.NotNull; +import java.io.*; +import java.time.LocalDateTime; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.logging.ConsoleHandler; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * @author Ruben Bermudez + * @version 2.0 + * @brief Logger to file + * @date 21/01/15 + */ +public class BotLogger { + private static final Object lockToWrite = new Object(); + private static volatile PrintWriter logginFile; + private static volatile String currentFileName; + private static final Logger logger = Logger.getLogger("Tsupport Bot"); + private static volatile LocalDateTime lastFileDate; + private static LoggerThread loggerThread = new LoggerThread(); + private static final ConcurrentLinkedQueue logsToFile = new ConcurrentLinkedQueue<>(); + + static { + logger.setLevel(Level.ALL); + logger.addHandler(new ConsoleHandler()); + loggerThread.start(); + lastFileDate = LocalDateTime.now(); + if ((currentFileName == null) || (currentFileName.compareTo("") == 0)) { + currentFileName = dateFormatterForFileName(lastFileDate) + ".log"; + try { + final File file = new File(currentFileName); + if (file.exists()) { + logginFile = new PrintWriter(new BufferedWriter(new FileWriter(currentFileName, true))); + } else { + final boolean created = file.createNewFile(); + if (created) { + logginFile = new PrintWriter(new BufferedWriter(new FileWriter(currentFileName, true))); + } else { + throw new NullPointerException("File for logging error"); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + + } + } + + public static void log(@NotNull Level level, String tag, String msg) { + logger.log(level, String.format("[%s] %s", tag, msg)); + logToFile(level, tag, msg); + } + + + public static void severe(String tag, String msg) { + logger.severe(String.format("[%s] %s", tag, msg)); + logToFile(Level.SEVERE, tag, msg); + } + + public static void warn(String tag, String msg) { + warning(tag, msg); + } + + public static void debug(String tag, String msg) { + fine(tag, msg); + } + + public static void error(String tag, String msg) { + severe(tag, msg); + } + + public static void trace(String tag, String msg) { + finer(tag, msg); + } + + public static void warning(String tag, String msg) { + logger.warning(String.format("[%s] %s", tag, msg)); + logToFile(Level.WARNING, tag, msg); + } + + + public static void info(String tag, String msg) { + logger.info(String.format("[%s] %s", tag, msg)); + logToFile(Level.INFO, tag, msg); + } + + + public static void config(String tag, String msg) { + logger.config(String.format("[%s] %s", tag, msg)); + logToFile(Level.CONFIG, tag, msg); + } + + + public static void fine(String tag, String msg) { + logger.fine(String.format("[%s] %s", tag, msg)); + logToFile(Level.FINE, tag, msg); + } + + + public static void finer(String tag, String msg) { + logger.finer(String.format("[%s] %s", tag, msg)); + logToFile(Level.FINER, tag, msg); + } + + + public static void finest(String tag, String msg) { + logger.finest(String.format("[%s] %s", tag, msg)); + logToFile(Level.FINEST, tag, msg); + } + + + public static void log(@NotNull Level level, @NotNull String tag, @NotNull Throwable throwable) { + logger.log(level, String.format("[%s] Exception", tag), throwable); + logToFile(level, tag, throwable); + } + + public static void log(@NotNull Level level, @NotNull String tag, @NotNull String msg, @NotNull Throwable thrown) { + logger.log(level, msg, thrown); + logToFile(level, msg, thrown); + } + + public static void severe(@NotNull String tag, @NotNull Throwable throwable) { + logToFile(Level.SEVERE, tag, throwable); + } + + public static void warning(@NotNull String tag, @NotNull Throwable throwable) { + logToFile(Level.WARNING, tag, throwable); + } + + public static void info(@NotNull String tag, @NotNull Throwable throwable) { + logToFile(Level.INFO, tag, throwable); + } + + public static void config(@NotNull String tag, @NotNull Throwable throwable) { + logToFile(Level.CONFIG, tag, throwable); + } + + public static void fine(@NotNull String tag, @NotNull Throwable throwable) { + logToFile(Level.FINE, tag, throwable); + } + + public static void finer(@NotNull String tag, @NotNull Throwable throwable) { + logToFile(Level.FINER, tag, throwable); + } + + public static void finest(@NotNull String tag, @NotNull Throwable throwable) { + logToFile(Level.FINEST, tag, throwable); + } + + public static void warn(@NotNull String tag, Throwable throwable) { + warning(tag, throwable); + } + + public static void debug(@NotNull String tag, Throwable throwable) { + fine(tag, throwable); + } + + public static void error(@NotNull String tag, Throwable throwable) { + severe(tag, throwable); + } + + public static void trace(@NotNull String tag, Throwable throwable) { + finer(tag, throwable); + } + + public static void severe(@NotNull String msg, @NotNull String tag, @NotNull Throwable throwable) { + log(Level.SEVERE, tag, msg, throwable); + } + + public static void warning(@NotNull String msg, @NotNull String tag, @NotNull Throwable throwable) { + log(Level.WARNING, tag, msg, throwable); + } + + public static void info(@NotNull String msg, @NotNull String tag, @NotNull Throwable throwable) { + log(Level.INFO, tag, msg, throwable); + } + + public static void config(@NotNull String msg, @NotNull String tag, @NotNull Throwable throwable) { + log(Level.CONFIG, tag, msg, throwable); + } + + public static void fine(@NotNull String msg, @NotNull String tag, @NotNull Throwable throwable) { + log(Level.FINE, tag, msg, throwable); + } + + public static void finer(@NotNull String msg, @NotNull String tag, @NotNull Throwable throwable) { + log(Level.FINER, tag, msg, throwable); + } + + public static void finest(@NotNull String msg, @NotNull String tag, @NotNull Throwable throwable) { + log(Level.FINEST, msg, throwable); + } + + public static void warn(@NotNull String msg, @NotNull String tag, @NotNull Throwable throwable) { + log(Level.WARNING, tag, msg, throwable); + } + + public static void debug(@NotNull String msg, @NotNull String tag, @NotNull Throwable throwable) { + log(Level.FINE, tag, msg, throwable); + } + + public static void error(@NotNull String msg, @NotNull String tag, @NotNull Throwable throwable) { + log(Level.SEVERE, tag, msg, throwable); + } + + public static void trace(@NotNull String msg, @NotNull String tag, @NotNull Throwable throwable) { + log(Level.FINER, tag, msg, throwable); + } + + private static boolean isCurrentDate(LocalDateTime dateTime) { + return dateTime.toLocalDate().isEqual(lastFileDate.toLocalDate()); + } + + private static String dateFormatterForFileName(@NotNull LocalDateTime dateTime) { + String dateString = ""; + dateString += dateTime.getDayOfMonth(); + dateString += dateTime.getMonthValue(); + dateString += dateTime.getYear(); + return dateString; + } + + private static String dateFormatterForLogs(@NotNull LocalDateTime dateTime) { + String dateString = "["; + dateString += dateTime.getDayOfMonth() + "_"; + dateString += dateTime.getMonthValue() + "_"; + dateString += dateTime.getYear() + "_"; + dateString += dateTime.getHour() + ":"; + dateString += dateTime.getMinute() + ":"; + dateString += dateTime.getSecond(); + dateString += "] "; + return dateString; + } + + private static void updateAndCreateFile(LocalDateTime dateTime) { + if (!isCurrentDate(dateTime)) { + lastFileDate = LocalDateTime.now(); + currentFileName = BuildVars.pathToLogs + dateFormatterForFileName(lastFileDate) + ".log"; + try { + logginFile.flush(); + logginFile.close(); + final File file = new File(currentFileName); + if (file.exists()) { + logginFile = new PrintWriter(new BufferedWriter(new FileWriter(currentFileName, true))); + } else { + final boolean created = file.createNewFile(); + if (created) { + logginFile = new PrintWriter(new BufferedWriter(new FileWriter(currentFileName, true))); + } else { + throw new NullPointerException("Error updating log file"); + } + } + } catch (IOException ignored) { + } + } + } + + + private static void logToFile(@NotNull Level level, @NotNull String tag, @NotNull Throwable throwable) { + if (isLoggable(level)) { + synchronized (lockToWrite) { + final LocalDateTime currentDate = LocalDateTime.now(); + final String dateForLog = dateFormatterForLogs(currentDate); + updateAndCreateFile(currentDate); + logThrowableToFile(level, tag, throwable, dateForLog); + } + } + } + + + + private static void logToFile(@NotNull Level level, @NotNull String tag, @NotNull String msg) { + if (isLoggable(level)) { + synchronized (lockToWrite) { + final LocalDateTime currentDate = LocalDateTime.now(); + updateAndCreateFile(currentDate); + final String dateForLog = dateFormatterForLogs(currentDate); + logMsgToFile(level, tag, msg, dateForLog); + } + } + } + + private static void logToFile(Level level, @NotNull String tag, @NotNull String msg, @NotNull Throwable throwable) { + if (isLoggable(level)) { + synchronized (lockToWrite) { + final LocalDateTime currentDate = LocalDateTime.now(); + updateAndCreateFile(currentDate); + final String dateForLog = dateFormatterForLogs(currentDate); + logMsgToFile(level, tag, msg, dateForLog); + logThrowableToFile(level, tag, throwable, dateForLog); + } + } + } + + private static void logMsgToFile(@NotNull Level level, @NotNull String tag, @NotNull String msg, @NotNull String dateForLog) { + final String logMessage = String.format("%s{%s} %s - %s", dateForLog, level.toString(), tag, msg); + logsToFile.add(logMessage); + synchronized (logsToFile) { + logsToFile.notifyAll(); + } + } + + private static void logThrowableToFile(@NotNull Level level, @NotNull String tag, @NotNull Throwable throwable, @NotNull String dateForLog) { + String throwableLog = String.format("%s{%s} %s - %s", dateForLog, level.toString(), tag, throwable.toString()); + for (StackTraceElement element : throwable.getStackTrace()) { + throwableLog += "\tat " + element + "\n"; + } + logsToFile.add(throwableLog); + synchronized (logsToFile) { + logsToFile.notifyAll(); + } + } + + private static boolean isLoggable(Level level) { + return logger.isLoggable(level) && BuildVars.debug; + } + + private static class LoggerThread extends Thread { + + @Override + public void run() { + while(true) { + final ConcurrentLinkedQueue stringsToLog = new ConcurrentLinkedQueue<>(); + synchronized (logsToFile) { + if (logsToFile.isEmpty()) { + try { + logsToFile.wait(); + } catch (InterruptedException e) { + return; + } + if (logsToFile.isEmpty()) { + continue; + } + } + stringsToLog.addAll(logsToFile); + logsToFile.clear(); + } + + stringsToLog.stream().forEach(logginFile::println); + logginFile.flush(); + } + } + } +} diff --git a/src/main/java/org/telegram/updateshandlers/SentCallback.java b/src/main/java/org/telegram/updateshandlers/SentCallback.java new file mode 100644 index 00000000..24d6839f --- /dev/null +++ b/src/main/java/org/telegram/updateshandlers/SentCallback.java @@ -0,0 +1,26 @@ +package org.telegram.updateshandlers; + +import org.json.JSONObject; +import org.telegram.api.methods.BotApiMethod; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Callback to execute api method asynchronously + * @date 10 of September of 2015 + */ +public interface SentCallback { + /** + * Called when the request is successful + * @param method Method executed + * @param jsonObject Answer from Telegram server + */ + void onResult(BotApiMethod method, JSONObject jsonObject); + + /** + * Called when the request fails + * @param method Method executed + * @param jsonObject Answer from Telegram server (contains error information) + */ + void onError(BotApiMethod method, JSONObject jsonObject); +} diff --git a/src/main/java/org/telegram/updateshandlers/UpdatesCallback.java b/src/main/java/org/telegram/updateshandlers/UpdatesCallback.java new file mode 100644 index 00000000..ee9469a8 --- /dev/null +++ b/src/main/java/org/telegram/updateshandlers/UpdatesCallback.java @@ -0,0 +1,24 @@ +package org.telegram.updateshandlers; + +import org.telegram.api.objects.Update; +import org.telegram.api.methods.BotApiMethod; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Callback to handle updates. Must support both, single update and List of updates + * @date 20 of June of 2015 + */ +public interface UpdatesCallback { + /** + * This method is called when receiving updates via org.telegram.api.methods.GetUpdates method + * @param update Update received + */ + void onUpdateReceived(Update update); + + /** + * This method is called when receiving updates via webhook + * @param update Update received + */ + BotApiMethod onWebhookUpdateReceived(Update update); +} diff --git a/src/main/java/org/telegram/updatesreceivers/RestApi.java b/src/main/java/org/telegram/updatesreceivers/RestApi.java new file mode 100644 index 00000000..08d0d503 --- /dev/null +++ b/src/main/java/org/telegram/updatesreceivers/RestApi.java @@ -0,0 +1,52 @@ +package org.telegram.updatesreceivers; + +import org.telegram.api.objects.Update; +import org.telegram.updateshandlers.UpdatesCallback; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Rest api to for webhook callback function + * @date 20 of June of 2015 + */ +@Path("callback") +public class RestApi { + + private final ConcurrentHashMap callbacks = new ConcurrentHashMap<>(); + + public RestApi() { + } + + public void registerCallback(UpdatesCallback callback, String botName) { + if (!callbacks.containsKey(botName)) { + callbacks.put(botName, callback); + } + } + + @POST + @Path("/{botname}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response updateReceived(@PathParam("botname") String botname, Update update) { + if (callbacks.containsKey(botname)) { + return Response.ok(this.callbacks.get(botname).onWebhookUpdateReceived(update)).build(); + } + return Response.ok().build(); + } + + @GET + @Path("/{botname}") + @Produces(MediaType.APPLICATION_JSON) + public String testReceived(@PathParam("botname") String botname) { + if (callbacks.containsKey(botname)) { + return "Hi there " + botname + "!"; + } else { + return "Callback not found for " + botname; + } + } +} diff --git a/src/main/java/org/telegram/updatesreceivers/UpdatesThread.java b/src/main/java/org/telegram/updatesreceivers/UpdatesThread.java new file mode 100644 index 00000000..987a2e9e --- /dev/null +++ b/src/main/java/org/telegram/updatesreceivers/UpdatesThread.java @@ -0,0 +1,141 @@ +package org.telegram.updatesreceivers; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.entity.BufferedHttpEntity; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.telegram.api.objects.Update; +import org.telegram.api.methods.Constants; +import org.telegram.api.methods.GetUpdates; +import org.telegram.services.BotLogger; +import org.telegram.updateshandlers.UpdatesCallback; + +import java.io.IOException; +import java.io.InvalidObjectException; +import java.util.concurrent.ConcurrentLinkedDeque; +import java.util.concurrent.TimeUnit; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Thread to request updates with active wait + * @date 20 of June of 2015 + */ +public class UpdatesThread { + private static final String LOGTAG = "UPDATESTHREAD"; + + private final UpdatesCallback callback; + private final ReaderThread readerThread; + private final HandlerThread handlerThread; + private int lastReceivedUpdate = 0; + private String token; + private final ConcurrentLinkedDeque receivedUpdates = new ConcurrentLinkedDeque<>(); + + public UpdatesThread(String token, UpdatesCallback callback) { + this.token = token; + this.callback = callback; + this.readerThread = new ReaderThread(); + this.readerThread.start(); + this.handlerThread = new HandlerThread(); + this.handlerThread.start(); + } + + private class ReaderThread extends Thread { + @Override + public void run() { + setPriority(Thread.MIN_PRIORITY); + while(true) { + GetUpdates request = new GetUpdates(); + request.setLimit(100); + request.setTimeout(20); + request.setOffset(lastReceivedUpdate + 1); + CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionTimeToLive(20, TimeUnit.SECONDS).build(); + String url = Constants.BASEURL + token + "/" + GetUpdates.PATH; + HttpPost httpPost = new HttpPost(url); + try { + httpPost.addHeader("charset", "UTF-8"); + httpPost.setEntity(new StringEntity(request.toJson().toString(), ContentType.APPLICATION_JSON)); + HttpResponse response; + BotLogger.debug(LOGTAG, httpPost.toString()); + response = httpclient.execute(httpPost); + HttpEntity ht = response.getEntity(); + + BufferedHttpEntity buf = new BufferedHttpEntity(ht); + String responseContent = EntityUtils.toString(buf, "UTF-8"); + + try { + JSONObject jsonObject = new JSONObject(responseContent); + if (!jsonObject.getBoolean("ok")) { + throw new InvalidObjectException(jsonObject.toString()); + } + JSONArray jsonArray = jsonObject.getJSONArray("result"); + BotLogger.debug(LOGTAG, jsonArray.toString()); + if (jsonArray.length() != 0) { + for (int i = 0; i < jsonArray.length(); i++) { + Update update = new Update(jsonArray.getJSONObject(i)); + if (update.getUpdateId() > lastReceivedUpdate) { + lastReceivedUpdate = update.getUpdateId(); + receivedUpdates.addFirst(update); + } + } + synchronized (receivedUpdates) { + receivedUpdates.notifyAll(); + } + } else { + try { + synchronized (this) { + this.wait(500); + } + } catch (InterruptedException e) { + BotLogger.error(LOGTAG, e); + continue; + } + } + } catch (JSONException e) { + BotLogger.warn(LOGTAG, e); + } + } catch (IOException e) { + BotLogger.warn(LOGTAG, e); + } + } + } + } + + private class HandlerThread extends Thread { + @Override + public void run() { + setPriority(Thread.MIN_PRIORITY); + while(true) { + try { + Update update = receivedUpdates.pollLast(); + if (update == null) { + synchronized (receivedUpdates) { + try { + receivedUpdates.wait(); + } catch (InterruptedException e) { + BotLogger.error(LOGTAG, e); + continue; + } + update = receivedUpdates.pollLast(); + if (update == null) { + continue; + } + } + } + callback.onUpdateReceived(update); + } catch (Exception e) { + BotLogger.error(LOGTAG, e); + } + } + } + } +} diff --git a/src/main/java/org/telegram/updatesreceivers/Webhook.java b/src/main/java/org/telegram/updatesreceivers/Webhook.java new file mode 100644 index 00000000..023094c4 --- /dev/null +++ b/src/main/java/org/telegram/updatesreceivers/Webhook.java @@ -0,0 +1,83 @@ +package org.telegram.updatesreceivers; + +import com.sun.jersey.api.json.JSONConfiguration; +import org.glassfish.grizzly.http.server.HttpServer; +import org.glassfish.grizzly.ssl.SSLContextConfigurator; +import org.glassfish.grizzly.ssl.SSLEngineConfigurator; +import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; +import org.glassfish.jersey.jackson.JacksonFeature; +import org.glassfish.jersey.server.ResourceConfig; +import org.telegram.services.BotLogger; +import org.telegram.updateshandlers.UpdatesCallback; + +import java.io.IOException; +import java.net.URI; + +/** + * @author Ruben Bermudez + * @version 1.0 + * @brief Webhook to receive updates + * @date 20 of June of 2015 + */ +public class Webhook { + private static final String LOGTAG = "WEBHOOK"; + + private final String KEYSTORE_SERVER_FILE; + private final String KEYSTORE_SERVER_PWD; + + private final RestApi restApi; + private final String externalUrl; + private final String internalUrl; + + public Webhook(String keyStore, String keyStorePassword, String externalUrl, String internalUrl) { + this.KEYSTORE_SERVER_FILE = keyStore; + this.KEYSTORE_SERVER_PWD = keyStorePassword; + this.externalUrl = externalUrl; + this.internalUrl = internalUrl; + this.restApi = new RestApi(); + } + + public void registerWebhook(UpdatesCallback callback, String botName) { + restApi.registerCallback(callback, botName); + } + + public void startServer() { + SSLContextConfigurator sslContext = new SSLContextConfigurator(); + + // set up security context + sslContext.setKeyStoreFile(KEYSTORE_SERVER_FILE); // contains server keypair + sslContext.setKeyStorePass(KEYSTORE_SERVER_PWD); + + ResourceConfig rc = new ResourceConfig(); + rc.register(restApi); + rc.register(JacksonFeature.class); + rc.property(JSONConfiguration.FEATURE_POJO_MAPPING, true); + BotLogger.info(LOGTAG, "Internal webhook: " + getBaseURI().toString()); + final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer( + getBaseURI(), + rc, + true, + new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false)); + try { + grizzlyServer.start(); + } catch (IOException e) { + BotLogger.error(LOGTAG, e); + } + } + + public void startDebugServer() { + ResourceConfig rc = new ResourceConfig(); + rc.register(restApi); + rc.register(JacksonFeature.class); + rc.property(JSONConfiguration.FEATURE_POJO_MAPPING, true); + GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc); + } + + public String getExternalURL(String botName) { + return String.format("%s/callback/%s", externalUrl, botName); + } + + private URI getBaseURI() { + return URI.create(internalUrl); + } + }