├── docs ├── CNAME ├── main.css └── index.html ├── src ├── it │ ├── simple-it │ │ ├── invoker.properties │ │ ├── src │ │ │ ├── main │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── elegramapi │ │ │ │ │ └── simpleit │ │ │ │ │ ├── package-info.java │ │ │ │ │ └── ItSimple.java │ │ │ └── test │ │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── elegramapi │ │ │ │ │ └── simpleit │ │ │ │ │ ├── package-info.java │ │ │ │ │ └── ItSimpleTest.java │ │ │ │ └── resources │ │ │ │ └── log4j.properties │ │ └── pom.xml │ └── settings.xml ├── main │ └── java │ │ └── ru │ │ └── elegramapi │ │ └── www │ │ ├── update │ │ ├── package-info.java │ │ └── UpdDefault.java │ │ ├── package-info.java │ │ ├── bot │ │ ├── package-info.java │ │ ├── BtLogged.java │ │ └── BtDefault.java │ │ ├── command │ │ └── package-info.java │ │ ├── message │ │ ├── package-info.java │ │ └── Message.java │ │ ├── fake │ │ ├── package-info.java │ │ └── FkJMessage.java │ │ ├── request │ │ ├── package-info.java │ │ ├── TRqGetMe.java │ │ ├── TRqSendMessage.java │ │ ├── TRqGetUpdates.java │ │ ├── TRqGetFile.java │ │ ├── TRqPost.java │ │ ├── TRqWithOffset.java │ │ ├── TRqWithText.java │ │ ├── TRqWithChatId.java │ │ └── TRqEnvelope.java │ │ ├── Update.java │ │ ├── Command.java │ │ ├── Bot.java │ │ └── TelegramRequest.java └── test │ └── java │ └── ru │ └── elegramapi │ └── www │ ├── bot │ └── package-info.java │ ├── package-info.java │ ├── message │ ├── package-info.java │ └── MessageTest.java │ └── request │ ├── package-info.java │ ├── TRqPostTest.java │ ├── RqGetMeTelegramTest.java │ ├── RqGetUpdatesTelegramTest.java │ ├── RqGetFileTelegramTest.java │ ├── RqSendMessageTelegramTest.java │ ├── TRqWithChatIdTest.java │ ├── TRqWithOffsetTest.java │ └── TRqWithTextTest.java ├── .0pdd.yml ├── .pdd ├── renovate.json ├── .github └── workflows │ ├── pdd.yaml │ ├── xcop.yaml │ ├── year.yaml │ ├── codecov.yaml │ └── mvn.yaml ├── .gitignore ├── .rultor.yml ├── LICENSE.txt ├── README.md └── pom.xml /docs/CNAME: -------------------------------------------------------------------------------- 1 | www.elegram-api.ru -------------------------------------------------------------------------------- /src/it/simple-it/invoker.properties: -------------------------------------------------------------------------------- 1 | invoker.goals = clean test 2 | -------------------------------------------------------------------------------- /.0pdd.yml: -------------------------------------------------------------------------------- 1 | errors: 2 | - l3r8y@duck.com 3 | tags: 4 | - pdd 5 | - bug 6 | -------------------------------------------------------------------------------- /.pdd: -------------------------------------------------------------------------------- 1 | --source=. 2 | --verbose 3 | --exclude target/** 4 | --rule min-words:10 5 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:base" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.github/workflows/pdd.yaml: -------------------------------------------------------------------------------- 1 | name: pdd 2 | on: 3 | push: 4 | pull_request: 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - uses: g4s8/pdd-action@master 11 | -------------------------------------------------------------------------------- /.github/workflows/xcop.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: xcop 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | jobs: 11 | xcop: 12 | runs-on: ubuntu-20.04 13 | steps: 14 | - uses: actions/checkout@v3 15 | - uses: g4s8/xcop-action@master 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | .idea 26 | **/.DS_Store 27 | 28 | target 29 | -------------------------------------------------------------------------------- /.rultor.yml: -------------------------------------------------------------------------------- 1 | architect: 2 | - l3r8yJ 3 | secrets: 4 | settings.xml: l3r8yJ/home#assets/settings.xml 5 | merge: 6 | script: 7 | - "mvn clean install -Pqulice --errors --batch-mode" 8 | release: 9 | pre: false 10 | sensetive: 11 | - settings.xml 12 | script: |- 13 | [[ "${tag}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit -1 14 | mvn versions:set "-DnewVersion=${tag}" 15 | git commit -am "${tag}" 16 | mvn clean deploy -Pqulice-profile -Pqulice -Psonatype --errors --settings ../settings.xml -------------------------------------------------------------------------------- /.github/workflows/year.yaml: -------------------------------------------------------------------------------- 1 | name: year 2 | on: 3 | schedule: 4 | - cron: '0 1 21 * *' # Runs at 01:00 UTC on the 22nd of every month 5 | jobs: 6 | license: 7 | runs-on: ubuntu-20.04 8 | steps: 9 | - uses: actions/checkout@v3 10 | with: 11 | fetch-depth: 0 12 | - uses: FantasticFiasco/action-update-license-year@v2 13 | with: 14 | token: ${{ secrets.TOKEN_GH }} 15 | path: | #add new path with glob pattern https://www.npmjs.com/package/glob 16 | **/^((?!.yaml).)*$ 17 | commitTitle: "update license year" 18 | -------------------------------------------------------------------------------- /.github/workflows/codecov.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: codecov 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | jobs: 9 | codecov: 10 | runs-on: ubuntu-20.04 11 | steps: 12 | - uses: actions/checkout@v2 13 | - uses: actions/setup-java@v3 14 | with: 15 | distribution: 'temurin' 16 | java-version: 17 17 | - uses: actions/cache@v3 18 | with: 19 | path: ~/.m2/repository 20 | key: maven-${{ hashFiles('**/pom.xml') }} 21 | restore-keys: | 22 | maven- 23 | - run: mvn clean install 24 | - uses: codecov/codecov-action@v3 25 | with: 26 | files: ./target/site/jacoco/jacoco.xml 27 | fail_ci_if_error: true 28 | -------------------------------------------------------------------------------- /.github/workflows/mvn.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: mvn 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | jobs: 11 | test: 12 | name: Tests 13 | strategy: 14 | matrix: 15 | os: [ubuntu-20.04, macos-12] 16 | java: [11, 17] 17 | runs-on: ${{ matrix.os }} 18 | steps: 19 | - uses: actions/checkout@v2 20 | - uses: actions/setup-java@v3 21 | with: 22 | distribution: 'temurin' 23 | java-version: ${{ matrix.java }} 24 | - uses: actions/cache@v3 25 | with: 26 | path: ~/.m2/repository 27 | key: ${{ runner.os }}-jdk-${{ matrix.java }}-maven-${{ hashFiles('**/pom.xml') }} 28 | restore-keys: | 29 | ${{ runner.os }}-jdk-${{ matrix.java }}-maven- 30 | - run: mvn clean install -Pqulice --errors --batch-mode 31 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2022-2023 Ivanchuck Ivan. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included 13 | in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/update/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * The update package. 27 | */ 28 | package ru.elegramapi.www.update; 29 | -------------------------------------------------------------------------------- /src/test/java/ru/elegramapi/www/bot/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * The test package for bot. 27 | */ 28 | package ru.elegramapi.www.bot; 29 | -------------------------------------------------------------------------------- /src/test/java/ru/elegramapi/www/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Test package. 27 | * 28 | * @since 0.0.0 29 | */ 30 | package ru.elegramapi.www; 31 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Elegram api module. 27 | * 28 | * @since 0.0.0 29 | */ 30 | package ru.elegramapi.www; 31 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/bot/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * The bot package. 27 | * 28 | * @since 0.0.0 29 | */ 30 | package ru.elegramapi.www.bot; 31 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/command/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * The commands package. 27 | * 28 | * @since 0.0.0 29 | */ 30 | package ru.elegramapi.www.command; 31 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/message/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * The message package. 27 | * 28 | * @since 0.0.0 29 | */ 30 | package ru.elegramapi.www.message; 31 | -------------------------------------------------------------------------------- /src/test/java/ru/elegramapi/www/message/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Message test package. 27 | * 28 | * @since 0.0.0 29 | */ 30 | package ru.elegramapi.www.message; 31 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/fake/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Package with fake objects and data. 27 | * 28 | * @since 0.0.0 29 | */ 30 | package ru.elegramapi.www.fake; 31 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/request/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Requests to telegram api. 27 | * 28 | * @since 0.0.0 29 | */ 30 | package ru.elegramapi.www.request; 31 | -------------------------------------------------------------------------------- /src/test/java/ru/elegramapi/www/request/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * The test module for requests. 27 | * 28 | * @since 0.0.0 29 | */ 30 | package ru.elegramapi.www.request; 31 | -------------------------------------------------------------------------------- /src/it/simple-it/src/main/java/com/elegramapi/simpleit/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Package with integration tests. 27 | * 28 | * @since 0.0.0 29 | */ 30 | package com.elegramapi.simpleit; 31 | -------------------------------------------------------------------------------- /src/it/simple-it/src/test/java/com/elegramapi/simpleit/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Package with integration tests. 27 | * 28 | * @since 0.0.0 29 | */ 30 | package com.elegramapi.simpleit; 31 | -------------------------------------------------------------------------------- /src/it/simple-it/src/main/java/com/elegramapi/simpleit/ItSimple.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.elegramapi.simpleit; 26 | 27 | /** 28 | * Simple integration test. 29 | * 30 | * @since 0.0.0 31 | */ 32 | public final class ItSimple { 33 | } 34 | -------------------------------------------------------------------------------- /src/it/simple-it/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # The MIT License (MIT) 3 | # 4 | # Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included 14 | # in all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | 25 | log4j.rootLogger=WARN, CONSOLE 26 | log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender 27 | log4j.appender.CONSOLE.layout=com.jcabi.log.MulticolorLayout 28 | log4j.appender.CONSOLE.layout.ConversionPattern=[%color{%p}] %t %c: %m%n 29 | 30 | log4j.logger.com.jcabi.github=DEBUG 31 | log4j.logger.com.jcabi.http=INFO 32 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/Update.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www; 26 | 27 | import ru.elegramapi.www.message.Message; 28 | 29 | /** 30 | * The update from api. 31 | * 32 | * @since 0.0.0 33 | */ 34 | public interface Update { 35 | 36 | /** 37 | * The update id. 38 | * 39 | * @return The id 40 | */ 41 | long updateId(); 42 | 43 | /** 44 | * The message. 45 | * 46 | * @return Just message from update 47 | */ 48 | Message message(); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/request/TRqGetMe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package ru.elegramapi.www.request; 25 | 26 | import org.cactoos.text.Concatenated; 27 | 28 | /** 29 | * GetMe request to telegram api. 30 | * 31 | * @since 0.0.0 32 | */ 33 | public final class TRqGetMe extends TRqEnvelope { 34 | 35 | /** 36 | * Ctor. 37 | * 38 | * @param token The token 39 | */ 40 | public TRqGetMe(final String token) { 41 | super(new Concatenated(token, "/getMe").toString()); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/request/TRqSendMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package ru.elegramapi.www.request; 25 | 26 | import org.cactoos.text.Concatenated; 27 | 28 | /** 29 | * Request to send message to the api. 30 | * 31 | * @since 0.0.0 32 | */ 33 | public class TRqSendMessage extends TRqEnvelope { 34 | 35 | /** 36 | * Ctor. 37 | * 38 | * @param token The token 39 | */ 40 | public TRqSendMessage(final String token) { 41 | super(new Concatenated(token, "/sendMessage").toString()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/request/TRqGetUpdates.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import org.cactoos.text.Concatenated; 28 | 29 | /** 30 | * GetUpdates request to telegram api. 31 | * 32 | * @since 0.0.0 33 | */ 34 | public final class TRqGetUpdates extends TRqEnvelope { 35 | 36 | /** 37 | * Ctor. 38 | * 39 | * @param token The token 40 | */ 41 | public TRqGetUpdates(final String token) { 42 | super(new Concatenated(token, "/getUpdates").toString()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/Command.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www; 26 | 27 | import java.io.IOException; 28 | 29 | /** 30 | * The base command. 31 | * 32 | * @since 0.0.0 33 | */ 34 | public interface Command { 35 | 36 | /** 37 | * The action of this command. 38 | * This method should be overloaded 39 | * to add new functionality to your bot. 40 | * 41 | * @param update The update 42 | * @param bot Bot to interact 43 | * @throws IOException When something went wrong. 44 | */ 45 | void act(Update update, Bot bot) throws IOException; 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/request/TRqGetFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import org.cactoos.text.Concatenated; 28 | 29 | /** 30 | * Request to file api. 31 | * 32 | * @since 0.0.0 33 | */ 34 | public class TRqGetFile extends TRqEnvelope { 35 | 36 | /** 37 | * The default address. 38 | */ 39 | private static final String ADDRESS = "https://api.telegram.org/file/bot"; 40 | 41 | /** 42 | * Ctor. 43 | * 44 | * @param token The token 45 | * @param path The path 46 | */ 47 | public TRqGetFile(final String token, final String path) { 48 | super( 49 | new Concatenated(token, "/", path).toString(), 50 | TRqGetFile.ADDRESS 51 | ); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/ru/elegramapi/www/request/TRqPostTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import java.io.IOException; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.Matchers; 30 | import org.junit.jupiter.api.Test; 31 | 32 | /** 33 | * Test case for {@link TRqPost}. 34 | * 35 | * @since 0.0.0 36 | */ 37 | class TRqPostTest { 38 | 39 | @Test 40 | void responsesWithPost() throws IOException { 41 | MatcherAssert.assertThat( 42 | "Is a POST request", 43 | new TRqPost(new TRqGetUpdates("tkn")) 44 | .response() 45 | .back() 46 | .toString() 47 | .contains("POST"), 48 | Matchers.equalTo(true) 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/Bot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package ru.elegramapi.www; 25 | 26 | import com.jcabi.http.response.JsonResponse; 27 | import java.io.IOException; 28 | 29 | /** 30 | * The Default bot. 31 | * 32 | * @since 0.0.0 33 | */ 34 | public interface Bot { 35 | 36 | /** 37 | * Runs the bot. 38 | * 39 | * @throws IOException If something went wrong 40 | * @throws InterruptedException If something was interrupted 41 | */ 42 | void start() throws InterruptedException, IOException; 43 | 44 | /** 45 | * Sends the message. 46 | * 47 | * @param chat Chat to send message 48 | * @param text Text for message 49 | * @return Response as Json 50 | * @throws IOException When something went wrong 51 | */ 52 | JsonResponse sendMessage(long chat, String text) throws IOException; 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/TelegramRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www; 26 | 27 | import com.jcabi.http.RequestURI; 28 | import com.jcabi.http.response.JsonResponse; 29 | import java.io.IOException; 30 | 31 | /** 32 | * Request to telegram-api. 33 | * 34 | * @since 0.0.0 35 | */ 36 | public interface TelegramRequest { 37 | 38 | /** 39 | * Represents RqTelegram in plain String. 40 | * 41 | * @return String value of RqTelegram 42 | */ 43 | String plainText(); 44 | 45 | /** 46 | * The response from request. 47 | * 48 | * @return The response 49 | * @throws IOException When something went wrong 50 | */ 51 | JsonResponse response() throws IOException; 52 | 53 | /** 54 | * The uri from request. 55 | * 56 | * @return The uri 57 | */ 58 | RequestURI uri(); 59 | } 60 | -------------------------------------------------------------------------------- /src/it/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 27 | 28 | it-repo 29 | 30 | true 31 | 32 | 33 | 34 | local.central 35 | @localRepositoryUrl@ 36 | 37 | true 38 | 39 | 40 | true 41 | 42 | 43 | 44 | 45 | 46 | local.central 47 | @localRepositoryUrl@ 48 | 49 | true 50 | 51 | 52 | true 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/test/java/ru/elegramapi/www/request/RqGetMeTelegramTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import java.io.IOException; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.Matchers; 30 | import org.junit.jupiter.api.Test; 31 | 32 | /** 33 | * Test case for {@link TRqGetMe}. 34 | * 35 | * @since 0.0.0 36 | */ 37 | class RqGetMeTelegramTest { 38 | 39 | /** 40 | * The link. 41 | */ 42 | private static final String LINK = "https://api.telegram.org/bottkn/getMe"; 43 | 44 | @Test 45 | final void representsAsPlainText() { 46 | MatcherAssert.assertThat( 47 | new TRqGetMe("tkn").plainText(), 48 | Matchers.equalTo(RqGetMeTelegramTest.LINK) 49 | ); 50 | } 51 | 52 | @Test 53 | final void responsesFromRightApiWorks() throws IOException { 54 | MatcherAssert.assertThat( 55 | new TRqGetMe("tkn") 56 | .response().back().uri().toString(), 57 | Matchers.equalTo(RqGetMeTelegramTest.LINK) 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/ru/elegramapi/www/request/RqGetUpdatesTelegramTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import java.io.IOException; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.Matchers; 30 | import org.junit.jupiter.api.Test; 31 | 32 | /** 33 | * Test case for {@link TRqGetUpdates}. 34 | * 35 | * @since 0.0.0 36 | */ 37 | class RqGetUpdatesTelegramTest { 38 | 39 | /** 40 | * The link. 41 | */ 42 | private static final String LINK = "https://api.telegram.org/bottkn/getUpdates"; 43 | 44 | @Test 45 | final void representsAsPlainText() { 46 | MatcherAssert.assertThat( 47 | new TRqGetUpdates("tkn").plainText(), 48 | Matchers.equalTo(RqGetUpdatesTelegramTest.LINK) 49 | ); 50 | } 51 | 52 | @Test 53 | final void responsesFromRightApiWorks() throws IOException { 54 | MatcherAssert.assertThat( 55 | new TRqGetUpdates("tkn") 56 | .response().back().uri().toString(), 57 | Matchers.equalTo(RqGetUpdatesTelegramTest.LINK) 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/ru/elegramapi/www/request/RqGetFileTelegramTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import java.io.IOException; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.Matchers; 30 | import org.junit.jupiter.api.Test; 31 | 32 | /** 33 | * Test case for {@link TRqGetFile}. 34 | * 35 | * @since 0.0.0 36 | */ 37 | class RqGetFileTelegramTest { 38 | 39 | /** 40 | * The address. 41 | */ 42 | private static final String ADDRESS = "https://api.telegram.org/file/bottkn/path"; 43 | 44 | @Test 45 | final void representsAsPlainText() { 46 | MatcherAssert.assertThat( 47 | new TRqGetFile("tkn", "path").plainText(), 48 | Matchers.equalTo(RqGetFileTelegramTest.ADDRESS) 49 | ); 50 | } 51 | 52 | @Test 53 | final void responsesFromRightApiWorks() throws IOException { 54 | MatcherAssert.assertThat( 55 | new TRqGetFile("tkn", "path") 56 | .response().back().uri().toString(), 57 | Matchers.equalTo(RqGetFileTelegramTest.ADDRESS) 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/ru/elegramapi/www/request/RqSendMessageTelegramTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import java.io.IOException; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.Matchers; 30 | import org.junit.jupiter.api.Test; 31 | 32 | /** 33 | * The test case for {@link TRqSendMessage}. 34 | * 35 | * @since 0.0.0 36 | */ 37 | class RqSendMessageTelegramTest { 38 | 39 | /** 40 | * The link. 41 | */ 42 | private static final String LINK = "https://api.telegram.org/bottkn/sendMessage"; 43 | 44 | @Test 45 | final void representsAsPlainText() { 46 | MatcherAssert.assertThat( 47 | new TRqSendMessage("tkn").plainText(), 48 | Matchers.equalTo(RqSendMessageTelegramTest.LINK) 49 | ); 50 | } 51 | 52 | @Test 53 | final void responsesFromRightApiWorks() throws IOException { 54 | MatcherAssert.assertThat( 55 | new TRqSendMessage("tkn") 56 | .response().back().uri().toString(), 57 | Matchers.equalTo(RqSendMessageTelegramTest.LINK) 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/fake/FkJMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.fake; 26 | 27 | import java.util.HashMap; 28 | import java.util.Map; 29 | import org.json.JSONObject; 30 | 31 | /** 32 | * The fake Message JSONObject with data. 33 | * 34 | * @since 0.0.0 35 | */ 36 | public final class FkJMessage { 37 | 38 | /** 39 | * Just test data. 40 | */ 41 | private final JSONObject wrapped; 42 | 43 | /** 44 | * Ctor. 45 | */ 46 | public FkJMessage() { 47 | this.wrapped = new JSONObject(); 48 | } 49 | 50 | /** 51 | * Represents data as json. 52 | * 53 | * @return The data 54 | */ 55 | public JSONObject asJson() { 56 | final Map from = new HashMap<>(0); 57 | from.put("id", 213L); 58 | final Map chat = new HashMap<>(0); 59 | chat.put("id", 132L); 60 | this.wrapped.put("message_id", 21L); 61 | this.wrapped.put("from", from); 62 | this.wrapped.put("chat", new JSONObject(chat)); 63 | this.wrapped.put("text", "Ruby, bark!"); 64 | this.wrapped.put("date", System.currentTimeMillis()); 65 | return this.wrapped; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/request/TRqPost.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import com.jcabi.http.RequestURI; 28 | import com.jcabi.http.request.JdkRequest; 29 | import com.jcabi.http.response.JsonResponse; 30 | import java.io.IOException; 31 | import ru.elegramapi.www.TelegramRequest; 32 | 33 | /** 34 | * Telegram request with POST. 35 | * This is a decorator for {@link TelegramRequest} 36 | * 37 | * @since 0.0.0 38 | */ 39 | public final class TRqPost implements TelegramRequest { 40 | 41 | /** 42 | * The origin request. 43 | */ 44 | private final TelegramRequest origin; 45 | 46 | /** 47 | * Ctor. 48 | * 49 | * @param origin The origin 50 | */ 51 | public TRqPost(final TelegramRequest origin) { 52 | this.origin = origin; 53 | } 54 | 55 | @Override 56 | public String plainText() { 57 | return this.origin.plainText(); 58 | } 59 | 60 | @Override 61 | public JsonResponse response() throws IOException { 62 | return new JdkRequest(this.uri().toString()) 63 | .method("POST") 64 | .fetch() 65 | .as(JsonResponse.class); 66 | } 67 | 68 | @Override 69 | public RequestURI uri() { 70 | return this.origin.uri(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /docs/main.css: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | @import url('//fonts.googleapis.com/css?family=Inconsolata'); 25 | body { 26 | font-family: 'Inconsolata', monospace; 27 | font-size: 20px; 28 | line-height: 1.3em; 29 | padding: 1em; 30 | } 31 | section { 32 | width: 32em; 33 | max-width: 100%; 34 | margin-left: auto; 35 | margin-right: auto; 36 | } 37 | .logo { 38 | height: 128px; 39 | width: 128px; 40 | } 41 | a { 42 | text-decoration: none; 43 | color: inherit; 44 | background-image: linear-gradient(#000,#000); 45 | background-position: 0 0.95em; 46 | background-repeat: repeat-x; 47 | background-size: 1px 1px; 48 | } 49 | a:visited { 50 | color: inherit; 51 | } 52 | a:hover { 53 | text-decoration: none; 54 | background-image: linear-gradient(#268714,#268714); 55 | background-size: 2px 2px; 56 | } 57 | .center { 58 | text-align: center; 59 | width: 20em; 60 | max-width: 100%; 61 | padding: 1em; 62 | height: 5em; 63 | position: page; 64 | top: 0; 65 | left: 0; 66 | right: 0; 67 | margin: auto; 68 | font-family: monospace; 69 | font-size: 24px; 70 | border: 0; 71 | box-sizing: border-box; 72 | } 73 | p { 74 | margin: 1em 0; 75 | } 76 | div { 77 | padding: 10px; 78 | margin: 5px; 79 | display: block; 80 | } 81 | -------------------------------------------------------------------------------- /src/test/java/ru/elegramapi/www/request/TRqWithChatIdTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import java.io.IOException; 28 | import javax.ws.rs.core.Response; 29 | import org.hamcrest.MatcherAssert; 30 | import org.hamcrest.Matchers; 31 | import org.junit.jupiter.api.BeforeEach; 32 | import org.junit.jupiter.api.Test; 33 | import ru.elegramapi.www.TelegramRequest; 34 | 35 | /** 36 | * Test case for {@link TRqWithChatId}. 37 | * 38 | * @since 0.0.0 39 | */ 40 | final class TRqWithChatIdTest { 41 | 42 | /** 43 | * Under test request. 44 | */ 45 | private TelegramRequest request; 46 | 47 | @BeforeEach 48 | void setUp() { 49 | this.request = new TRqWithChatId( 50 | new TRqSendMessage("tkn"), 51 | 34 52 | ); 53 | } 54 | 55 | @Test 56 | void responsesWithNotFound() throws IOException { 57 | MatcherAssert.assertThat( 58 | this.request.response().status(), 59 | Matchers.equalTo(Response.Status.NOT_FOUND.getStatusCode()) 60 | ); 61 | } 62 | 63 | @Test 64 | void createsUriWithRightParam() { 65 | MatcherAssert.assertThat( 66 | this.request.uri().toString().contains("chat_id=34"), 67 | Matchers.equalTo(true) 68 | ); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/ru/elegramapi/www/request/TRqWithOffsetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import java.io.IOException; 28 | import javax.ws.rs.core.Response; 29 | import org.hamcrest.MatcherAssert; 30 | import org.hamcrest.Matchers; 31 | import org.junit.jupiter.api.BeforeEach; 32 | import org.junit.jupiter.api.Test; 33 | import ru.elegramapi.www.TelegramRequest; 34 | 35 | /** 36 | * Test case for {@link TRqWithOffset}. 37 | * 38 | * @since 0.0.0 39 | */ 40 | final class TRqWithOffsetTest { 41 | 42 | /** 43 | * Under test request. 44 | */ 45 | private TelegramRequest request; 46 | 47 | @BeforeEach 48 | void setUp() { 49 | this.request = new TRqWithOffset( 50 | new TRqSendMessage("tkn"), 51 | 32 52 | ); 53 | } 54 | 55 | @Test 56 | void responsesWithNotFound() throws IOException { 57 | MatcherAssert.assertThat( 58 | this.request.response().status(), 59 | Matchers.equalTo(Response.Status.NOT_FOUND.getStatusCode()) 60 | ); 61 | } 62 | 63 | @Test 64 | void createsUriWithRightParam() { 65 | MatcherAssert.assertThat( 66 | this.request.uri().toString().contains("offset=32"), 67 | Matchers.equalTo(true) 68 | ); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/ru/elegramapi/www/request/TRqWithTextTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import java.io.IOException; 28 | import javax.ws.rs.core.Response; 29 | import org.hamcrest.MatcherAssert; 30 | import org.hamcrest.Matchers; 31 | import org.junit.jupiter.api.BeforeEach; 32 | import org.junit.jupiter.api.Test; 33 | import ru.elegramapi.www.TelegramRequest; 34 | 35 | /** 36 | * Test case for {@link TRqWithText}. 37 | * 38 | * @since 0.0.0 39 | */ 40 | final class TRqWithTextTest { 41 | 42 | /** 43 | * The under test request. 44 | */ 45 | private TelegramRequest request; 46 | 47 | @BeforeEach 48 | void setUp() { 49 | this.request = new TRqWithText( 50 | new TRqSendMessage("tkn"), 51 | "Hi, i'm Sonya!" 52 | ); 53 | } 54 | 55 | @Test 56 | void createsUriWithRightParam() { 57 | MatcherAssert.assertThat( 58 | this.request.uri().toString().contains("text="), 59 | Matchers.equalTo(true) 60 | ); 61 | } 62 | 63 | @Test 64 | void responsesWithNotFound() throws IOException { 65 | MatcherAssert.assertThat( 66 | this.request.response().status(), 67 | Matchers.equalTo(Response.Status.NOT_FOUND.getStatusCode()) 68 | ); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/request/TRqWithOffset.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import com.jcabi.http.RequestURI; 28 | import com.jcabi.http.request.JdkRequest; 29 | import com.jcabi.http.response.JsonResponse; 30 | import java.io.IOException; 31 | import ru.elegramapi.www.TelegramRequest; 32 | 33 | /** 34 | * Decorator for {@link TelegramRequest}. 35 | * Adds offset to request. 36 | * 37 | * @since 0.0.0 38 | */ 39 | public final class TRqWithOffset implements TelegramRequest { 40 | 41 | /** 42 | * The origin. 43 | */ 44 | private final TelegramRequest origin; 45 | 46 | /** 47 | * The offset. 48 | */ 49 | private final int offset; 50 | 51 | /** 52 | * Ctor. 53 | * 54 | * @param origin The origin. 55 | * @param offset The offset. 56 | */ 57 | public TRqWithOffset(final TelegramRequest origin, final int offset) { 58 | this.origin = origin; 59 | this.offset = offset; 60 | } 61 | 62 | @Override 63 | public String plainText() { 64 | return this.uri().toString(); 65 | } 66 | 67 | @Override 68 | public JsonResponse response() throws IOException { 69 | return new JdkRequest(this.uri().toString()) 70 | .fetch() 71 | .as(JsonResponse.class); 72 | } 73 | 74 | @Override 75 | public RequestURI uri() { 76 | return this.origin.uri().queryParam("offset", this.offset); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/request/TRqWithText.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import com.jcabi.http.RequestURI; 28 | import com.jcabi.http.request.JdkRequest; 29 | import com.jcabi.http.response.JsonResponse; 30 | import java.io.IOException; 31 | import ru.elegramapi.www.TelegramRequest; 32 | 33 | /** 34 | * Telegram request with text. 35 | * This is a decorator for {@link TelegramRequest} inheritors. 36 | * 37 | * @since 0.0.0 38 | */ 39 | public final class TRqWithText implements TelegramRequest { 40 | 41 | /** 42 | * The origin. 43 | */ 44 | private final TelegramRequest origin; 45 | 46 | /** 47 | * The text. 48 | */ 49 | private final String text; 50 | 51 | /** 52 | * Ctor. 53 | * 54 | * @param origin The origin request 55 | * @param text The text to add 56 | */ 57 | public TRqWithText(final TelegramRequest origin, final String text) { 58 | this.origin = origin; 59 | this.text = text; 60 | } 61 | 62 | @Override 63 | public String plainText() { 64 | return this.uri().toString(); 65 | } 66 | 67 | @Override 68 | public JsonResponse response() throws IOException { 69 | return new JdkRequest(this.uri().toString()) 70 | .fetch() 71 | .as(JsonResponse.class); 72 | } 73 | 74 | @Override 75 | public RequestURI uri() { 76 | return this.origin.uri().queryParam("text", this.text); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/request/TRqWithChatId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import com.jcabi.http.RequestURI; 28 | import com.jcabi.http.request.JdkRequest; 29 | import com.jcabi.http.response.JsonResponse; 30 | import java.io.IOException; 31 | import ru.elegramapi.www.TelegramRequest; 32 | 33 | /** 34 | * Telegram request with chat id as param. 35 | * This is a decorator for {@link TelegramRequest} inheritors. 36 | * 37 | * @since 0.0.0 38 | */ 39 | public final class TRqWithChatId implements TelegramRequest { 40 | 41 | /** 42 | * The origin. 43 | */ 44 | private final TelegramRequest origin; 45 | 46 | /** 47 | * The chat. 48 | */ 49 | private final long chat; 50 | 51 | /** 52 | * Ctor. 53 | * 54 | * @param origin Origin request 55 | * @param chat Chat id to add 56 | */ 57 | public TRqWithChatId(final TelegramRequest origin, final long chat) { 58 | this.origin = origin; 59 | this.chat = chat; 60 | } 61 | 62 | @Override 63 | public String plainText() { 64 | return this.uri().toString(); 65 | } 66 | 67 | @Override 68 | public JsonResponse response() throws IOException { 69 | return new JdkRequest(this.uri().toString()) 70 | .fetch() 71 | .as(JsonResponse.class); 72 | } 73 | 74 | @Override 75 | public RequestURI uri() { 76 | return this.origin.uri().queryParam("chat_id", this.chat); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/update/UpdDefault.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.update; 26 | 27 | import java.util.Objects; 28 | import org.json.JSONObject; 29 | import ru.elegramapi.www.Update; 30 | import ru.elegramapi.www.message.Message; 31 | 32 | /** 33 | * The default update. 34 | * 35 | * @since 0.0.0 36 | */ 37 | public final class UpdDefault implements Update { 38 | 39 | /** 40 | * Update as json. 41 | */ 42 | private final JSONObject json; 43 | 44 | /** 45 | * Handling for incoming update. 46 | * 47 | * @param update The update 48 | */ 49 | public UpdDefault(final JSONObject update) { 50 | this.json = update; 51 | } 52 | 53 | @Override 54 | public long updateId() { 55 | return this.json.getLong("update_id"); 56 | } 57 | 58 | @Override 59 | public Message message() { 60 | return new Message(this.json.getJSONObject("message")); 61 | } 62 | 63 | @Override 64 | public int hashCode() { 65 | return Objects.hashCode(this.updateId()); 66 | } 67 | 68 | @Override 69 | @SuppressWarnings("PMD.OnlyOneReturn") 70 | public boolean equals(final Object obj) { 71 | if (this == obj) { 72 | return true; 73 | } 74 | if (null == obj || !this.getClass().equals(obj.getClass())) { 75 | return false; 76 | } 77 | final Update update = (Update) obj; 78 | return update.updateId() == this.updateId(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/message/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.message; 26 | 27 | import java.time.Instant; 28 | import org.json.JSONObject; 29 | 30 | /** 31 | * Just a message with all fields. 32 | * 33 | * @since 0.0.0 34 | */ 35 | public final class Message { 36 | 37 | /** 38 | * The json. 39 | */ 40 | private final JSONObject json; 41 | 42 | /** 43 | * Ctor. 44 | * 45 | * @param json Data from server 46 | */ 47 | public Message(final JSONObject json) { 48 | this.json = json; 49 | } 50 | 51 | /** 52 | * The message id. 53 | * 54 | * @return Just message id. 55 | */ 56 | public Long messageId() { 57 | return this.json.getLong("message_id"); 58 | } 59 | 60 | /** 61 | * The message id. 62 | * 63 | * @return Just message id. 64 | */ 65 | public Long senderId() { 66 | return this.json.getJSONObject("from").getLong("id"); 67 | } 68 | 69 | /** 70 | * The chat id. 71 | * 72 | * @return Just chat id. 73 | */ 74 | public Long chatId() { 75 | return this.json.getJSONObject("chat").getLong("id"); 76 | } 77 | 78 | /** 79 | * Get text of the message. 80 | * 81 | * @return Text of the message 82 | */ 83 | public String text() { 84 | return this.json.getString("text"); 85 | } 86 | 87 | /** 88 | * Get the date the message was sent in Unix time. 89 | * 90 | * @return Unix time 91 | */ 92 | public Instant date() { 93 | return Instant.ofEpochSecond(this.json.getLong("date")); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/test/java/ru/elegramapi/www/message/MessageTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.message; 26 | 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.Matchers; 29 | import org.junit.jupiter.api.BeforeEach; 30 | import org.junit.jupiter.api.Test; 31 | import ru.elegramapi.www.fake.FkJMessage; 32 | 33 | /** 34 | * Test case for {@link Message}. 35 | * 36 | * @since 0.0.0 37 | */ 38 | class MessageTest { 39 | 40 | /** 41 | * Under test message. 42 | */ 43 | private Message msg; 44 | 45 | @BeforeEach 46 | void setUp() { 47 | this.msg = new Message(new FkJMessage().asJson()); 48 | } 49 | 50 | @Test 51 | void containsMessageId() { 52 | MatcherAssert.assertThat( 53 | this.msg.messageId(), 54 | Matchers.equalTo( 55 | new FkJMessage().asJson().getLong("message_id") 56 | ) 57 | ); 58 | } 59 | 60 | @Test 61 | void containsSenderId() { 62 | MatcherAssert.assertThat( 63 | this.msg.senderId(), 64 | Matchers.equalTo( 65 | new FkJMessage() 66 | .asJson() 67 | .getJSONObject("from") 68 | .getLong("id") 69 | ) 70 | ); 71 | } 72 | 73 | @Test 74 | void containsChatId() { 75 | MatcherAssert.assertThat( 76 | this.msg.chatId(), 77 | Matchers.equalTo( 78 | new FkJMessage() 79 | .asJson() 80 | .getJSONObject("chat") 81 | .getLong("id") 82 | ) 83 | ); 84 | } 85 | 86 | @Test 87 | void containsText() { 88 | MatcherAssert.assertThat( 89 | this.msg.text(), 90 | Matchers.equalTo( 91 | new FkJMessage() 92 | .asJson() 93 | .getString("text") 94 | ) 95 | ); 96 | } 97 | 98 | @Test 99 | void containsDate() { 100 | MatcherAssert.assertThat( 101 | this.msg.date(), 102 | Matchers.notNullValue() 103 | ); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/bot/BtLogged.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.bot; 26 | 27 | import com.jcabi.http.response.JsonResponse; 28 | import com.jcabi.log.Logger; 29 | import java.io.IOException; 30 | import org.cactoos.text.FormattedText; 31 | import ru.elegramapi.www.Bot; 32 | 33 | /** 34 | * Decorator for {@link Bot}. 35 | * Logging for decorated bot. 36 | * 37 | * @since 0.0.0 38 | */ 39 | public final class BtLogged implements Bot { 40 | 41 | /** 42 | * The origin bot. 43 | */ 44 | private final Bot origin; 45 | 46 | /** 47 | * Ctor. 48 | * 49 | * @param origin The bot 50 | */ 51 | public BtLogged(final Bot origin) { 52 | this.origin = origin; 53 | } 54 | 55 | @Override 56 | public void start() { 57 | Logger.info( 58 | this, 59 | new FormattedText( 60 | "%s is started", 61 | this.origin.getClass().toString() 62 | ).toString() 63 | ); 64 | try { 65 | this.origin.start(); 66 | } catch (final IOException | InterruptedException ex) { 67 | throw new IllegalStateException( 68 | this.logErrorMessage("start", ex), 69 | ex 70 | ); 71 | } 72 | } 73 | 74 | @Override 75 | public JsonResponse sendMessage(final long chat, final String text) { 76 | Logger.info( 77 | this, 78 | new FormattedText( 79 | "#sendMessage: sending message to %d", 80 | chat 81 | ).toString() 82 | ); 83 | try { 84 | return this.origin.sendMessage(chat, text); 85 | } catch (final IOException ex) { 86 | throw new IllegalStateException( 87 | this.logErrorMessage("sendMessage", ex), 88 | ex 89 | ); 90 | } 91 | } 92 | 93 | /** 94 | * Log error and throw exception. 95 | * 96 | * @param method The method that called 97 | * @param exc The exception 98 | * @return Error as {@link String} and make log 99 | */ 100 | private String logErrorMessage(final String method, final Exception exc) { 101 | final String error = new FormattedText( 102 | "#%s: An error occurred. Cause: %s", 103 | method, 104 | exc.getMessage() 105 | ).toString(); 106 | Logger.error(this, error); 107 | return error; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/request/TRqEnvelope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package ru.elegramapi.www.request; 26 | 27 | import com.jcabi.http.Request; 28 | import com.jcabi.http.RequestURI; 29 | import com.jcabi.http.request.JdkRequest; 30 | import com.jcabi.http.response.JsonResponse; 31 | import java.io.IOException; 32 | import org.cactoos.text.Concatenated; 33 | import ru.elegramapi.www.TelegramRequest; 34 | 35 | /** 36 | * Default request to telegram api without a method. 37 | * 38 | * @since 0.0.0 39 | */ 40 | public abstract class TRqEnvelope implements TelegramRequest { 41 | 42 | /** 43 | * Default url. 44 | */ 45 | private static final String DEFAULT_URL = "https://api.telegram.org/bot"; 46 | 47 | /** 48 | * Default telegram address. 49 | */ 50 | private final String address; 51 | 52 | /** 53 | * The uri to make request. 54 | */ 55 | private final String token; 56 | 57 | /** 58 | * The http request. 59 | */ 60 | private final Request request; 61 | 62 | /** 63 | * Ctor. 64 | * 65 | * @param token The token 66 | */ 67 | protected TRqEnvelope(final String token) { 68 | this( 69 | token, 70 | TRqEnvelope.DEFAULT_URL, 71 | new JdkRequest(new Concatenated(TRqEnvelope.DEFAULT_URL, token).toString()) 72 | ); 73 | } 74 | 75 | /** 76 | * Ctor. 77 | * 78 | * @param token The token 79 | * @param address The address 80 | */ 81 | protected TRqEnvelope(final String token, final String address) { 82 | this( 83 | token, 84 | address, 85 | new JdkRequest(new Concatenated(address, token).toString()) 86 | ); 87 | } 88 | 89 | /** 90 | * Ctor. 91 | * 92 | * @param token The token 93 | * @param address The address 94 | * @param request The http request 95 | */ 96 | protected TRqEnvelope( 97 | final String token, 98 | final String address, 99 | final Request request 100 | ) { 101 | this.token = token; 102 | this.address = address; 103 | this.request = request; 104 | } 105 | 106 | @Override 107 | public final String plainText() { 108 | return new Concatenated(this.address, this.token).toString(); 109 | } 110 | 111 | @Override 112 | public final JsonResponse response() throws IOException { 113 | return new JdkRequest(this.uri().get()).fetch().as(JsonResponse.class); 114 | } 115 | 116 | @Override 117 | public final RequestURI uri() { 118 | return this.request.uri(); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [logo](https://www.elegram-api.ru/) 2 | 3 | [![EO principles respected here](https://www.elegantobjects.org/badge.svg)](https://www.elegantobjects.org) 4 | [![DevOps By Rultor.com](http://www.rultor.com/b/objectionary/eo)](http://www.rultor.com/p/l3r8yJ/elegram-api) 5 | [![We recommend IntelliJ IDEA](https://www.elegantobjects.org/intellij-idea.svg)](https://www.jetbrains.com/idea/) 6 | 7 | [![PDD status](https://www.0pdd.com/svg?name=l3r8yJ/elegram-api)](https://www.0pdd.com/p?name=l3r8yJ/elegram-api) 8 | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/1c07f17c43f840758e9eed12be5e02af)](https://www.codacy.com/gh/l3r8yJ/elegram-api/dashboard?utm_source=github.com&utm_medium=referral&utm_content=l3r8yJ/elegram-api&utm_campaign=Badge_Grade) 9 | [![codecov](https://codecov.io/gh/l3r8yJ/elegram-api/branch/master/graph/badge.svg?token=JTWR1LR9QX)](https://codecov.io/gh/l3r8yJ/elegram-api) 10 | [![Hits-of-Code](https://hitsofcode.com/github/l3r8yJ/elegram-api)](https://hitsofcode.com/github/l3r8yJ/elegram-api/view) 11 | ![](https://img.shields.io/github/repo-size/l3r8yJ/elegram-api) 12 | 13 | __Elegram-api__ is a wrapper over the telegram bots api, but in the style of [EO](https://www.eolang.org). More object-oriented, more maintainable. 14 | ## Concept 15 | This is a concept, if you have ideas, feel free to create an issue! 16 | 17 | ```java 18 | import Bot; 19 | import Command; 20 | import Update; 21 | import BtDefault; 22 | import java.util.Objects; 23 | 24 | /** 25 | * Simple example. 26 | */ 27 | class App() { 28 | public static void main(String[] args) { 29 | new BtDefault( 30 | "your token", 31 | new CmdStart() 32 | ).start(); 33 | } 34 | } 35 | 36 | // this is a temporary solution, it will be changed later 37 | class CmdStart() extends Command { 38 | @Override 39 | public void act(final Update update, final Bot bot) { 40 | if (Objects.equals("/start", update.message().text())) { 41 | bot.sendMessage( 42 | update.message().chatId(), 43 | "Hi, this is a start command" 44 | ); 45 | } 46 | } 47 | } 48 | ``` 49 | ## Why does this project exist? 50 | This project solves the problem of the existing telegram-bots-api, which for some reason isn't _"Object-Oriented"_, 51 | here we can create a wrapper around the original API and make it more _"Object-Oriented"_. 52 | 53 | _What do I mean when I say object-oriented?_ 54 | > _So let's look at [cactoos](https://github.com/yegor256/cactoos) library, I think you get the idea._ 55 | ## How to Contribute 56 | Fork repository, make changes, send us a [pull request](https://www.yegor256.com/2014/04/15/github-guidelines.html). 57 | We will review your changes and apply them to the `master` branch shortly, 58 | provided they don't violate our quality standards. To avoid frustration, 59 | before sending us your pull request please run full Maven build: 60 | ```bash 61 | mvn clean install -Pqulice 62 | ``` 63 | You will need [Maven 3.3+](https://maven.apache.org) and Java 8+ installed 64 | ## Reasons to reject your code 65 | - [Empty lines.](https://www.yegor256.com/2014/11/03/empty-line-code-smell.html) 66 | - [Compound names.](https://www.yegor256.com/2015/01/12/compound-name-is-code-smell.html) 67 | - [Incorrect formatting.](https://www.yegor256.com/2014/10/23/paired-brackets-notation.html) 68 | - [Mutability.](https://www.yegor256.com/2014/06/09/objects-should-be-immutable.html) 69 | - [Getters/Setters.](https://www.yegor256.com/2014/09/16/getters-and-setters-are-evil.html) 70 | - [Static methods.](https://www.yegor256.com/2017/02/07/private-method-is-new-class.html) 71 | - [Pull request with feature but without unit-tests.](https://www.yegor256.com/2022/08/04/code-and-tests-different-pull-requests.html) 72 | 73 | This short list is supposed to make you understand that __we aren't picking on you__, it's just a __level of quality below which we can't accept__. 74 | ## Tests 75 | We're using [this plugin](https://github.com/volodya-lombrozo/test-naming-conventions) to control naming for tests, please note that. 76 | 77 | _Looking forward to your pull-request!_ 78 | 79 | 80 | ## Stargazers over time 81 | 82 | [![Stargazers over time](https://starchart.cc/l3r8yJ/elegram-api.svg)](https://starchart.cc/l3r8yJ/elegram-api) 83 | 84 | -------------------------------------------------------------------------------- /src/it/simple-it/src/test/java/com/elegramapi/simpleit/ItSimpleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.elegramapi.simpleit; 26 | 27 | import com.jcabi.http.response.JsonResponse; 28 | import java.io.IOException; 29 | import javax.ws.rs.core.Response; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.jupiter.api.Assertions; 33 | import org.junit.jupiter.api.BeforeEach; 34 | import org.junit.jupiter.api.Disabled; 35 | import org.junit.jupiter.api.Test; 36 | import ru.elegramapi.www.Bot; 37 | import ru.elegramapi.www.Command; 38 | import ru.elegramapi.www.Update; 39 | import ru.elegramapi.www.bot.BtDefault; 40 | import ru.elegramapi.www.bot.BtLogged; 41 | 42 | /** 43 | * Just simple integration test. 44 | * 45 | * @since 0.0.0 46 | */ 47 | final class ItSimpleTest { 48 | 49 | /** 50 | * Under test bot. 51 | */ 52 | private Bot bot; 53 | 54 | @BeforeEach 55 | void setUp() { 56 | this.bot = new BtLogged( 57 | new BtDefault( 58 | "5735860614:AAHsneN3fWj76dfXejtdSmNGLf4kq-bUGgg", 59 | new ItSimpleTest.CmdStart(), 60 | new ItSimpleTest.CmdEcho() 61 | ) 62 | ); 63 | } 64 | 65 | @Test 66 | @Disabled 67 | void runsTheBot() { 68 | Assertions.assertDoesNotThrow( 69 | () -> this.bot.start() 70 | ); 71 | } 72 | 73 | @Test 74 | void sendsTheMessage() throws IOException { 75 | final JsonResponse response = this.bot.sendMessage( 76 | 389_133_054L, 77 | "Hi, i'm Ruby!" 78 | ); 79 | MatcherAssert.assertThat( 80 | response.status(), 81 | Matchers.equalTo(Response.Status.OK.getStatusCode()) 82 | ); 83 | MatcherAssert.assertThat( 84 | response.back().toString().contains("POST"), 85 | Matchers.equalTo(true) 86 | ); 87 | } 88 | 89 | /** 90 | * The test command. 91 | * 92 | * @since 0.0.0 93 | */ 94 | private static class CmdStart implements Command { 95 | 96 | /** 97 | * Ctor. 98 | */ 99 | CmdStart() { 100 | // Test ctor. 101 | } 102 | 103 | @Override 104 | public final void act(final Update update, final Bot bot) throws IOException { 105 | if ("/start".equals(update.message().text())) { 106 | bot.sendMessage(update.message().chatId(), "Hi!"); 107 | } 108 | } 109 | } 110 | 111 | /** 112 | * The echo command. 113 | * 114 | * @since 0.0.0 115 | */ 116 | private static class CmdEcho implements Command { 117 | 118 | /** 119 | * Ctor. 120 | */ 121 | CmdEcho() { 122 | // Test ctor. 123 | } 124 | 125 | @Override 126 | public final void act(final Update update, final Bot bot) throws IOException { 127 | if (!update.message().text().isEmpty()) { 128 | bot.sendMessage( 129 | update.message().chatId(), 130 | update.message().text() 131 | ); 132 | } 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/it/simple-it/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 4.0.0 27 | org.l3r8yj 28 | simple-it 29 | jar 30 | 1.0-SNAPSHOT 31 | simple-it 32 | 33 | 1.8 34 | ${project.java.version} 35 | ${project.java.version} 36 | UTF-8 37 | 5.9.3 38 | 2.2 39 | 3.12.0 40 | 0.8.8 41 | 1.1.4 42 | 2.1 43 | 2.39.1 44 | 3.0.0 45 | 46 | 47 | 48 | @project.groupId@ 49 | @project.artifactId@ 50 | @project.version@ 51 | 52 | 53 | org.junit.jupiter 54 | junit-jupiter-api 55 | ${junit.version} 56 | test 57 | 58 | 59 | 60 | javax.json 61 | javax.json-api 62 | ${javax.json-api.version} 63 | 64 | 65 | javax.ws.rs 66 | javax.ws.rs-api 67 | ${javax.ws.rs-api.version} 68 | test 69 | 70 | 71 | org.glassfish.jersey.core 72 | jersey-common 73 | ${jersey-common.version} 74 | test 75 | 76 | 77 | org.hamcrest 78 | hamcrest 79 | ${hamcrest.version} 80 | test 81 | 82 | 83 | org.apache.commons 84 | commons-lang3 85 | ${commons-lang3.version} 86 | 87 | 88 | org.junit.jupiter 89 | junit-jupiter 90 | ${junit.version} 91 | test 92 | 93 | 94 | 95 | 96 | 97 | org.apache.maven.plugins 98 | maven-surefire-plugin 99 | ${maven-surefire-plugin.version} 100 | 101 | 102 | **/*Spec.* 103 | **/*Test.* 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 24 | 25 | 26 | 27 | 28 | elegram-api 29 | 30 | 31 | 32 | 34 | 35 | 36 | 51 | 52 | 53 |
54 |
55 |

56 | 58 |

59 |

elegram-api

60 |

61 | Elegram-api is a wrapper over the telegram bots api, but in the style of EO. More object-oriented, more maintainable. 62 |

63 |

64 | Check us out at Github. 65 |

66 |
67 |
68 |
69 |
70 |

How was the idea for this project born?

71 |

72 | I was baffled when I tried the libraries to interact with the telegram bot api, because I had never written such bad code before. 73 | All those endless configurations of objects through setters, changeable object state, class names that don't fit in one screen, side effects that come out of thin air. 74 | Libraries force us to write this garbage. After prolonged use of these libraries I got sick of it and so the idea of creating elegram-api was born. 75 |

76 |
77 |
78 |

Here some problems that I found in other projects:

79 | 88 |
89 |

90 | Let's see how bad code produces good solutions. 91 |

92 |
93 | 94 | 95 | -------------------------------------------------------------------------------- /src/main/java/ru/elegramapi/www/bot/BtDefault.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2022-2023 Ivanchuck Ivan. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included 14 | * in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | /* 25 | * @todo #60 Design/ Testing. 26 | * Write tests for DefaultBot class after closing other issues in DefaultBot class. 27 | * */ 28 | /* 29 | * @todo #106 Fix #handleUpdates. 30 | * This method work unpredictable, 31 | * need to fix work with incoming updates. 32 | * */ 33 | package ru.elegramapi.www.bot; 34 | 35 | import com.jcabi.http.response.JsonResponse; 36 | import java.io.IOException; 37 | import java.util.HashSet; 38 | import java.util.List; 39 | import java.util.Set; 40 | import java.util.concurrent.BlockingQueue; 41 | import java.util.concurrent.LinkedBlockingQueue; 42 | import java.util.concurrent.atomic.AtomicInteger; 43 | import org.cactoos.list.ListOf; 44 | import org.json.JSONArray; 45 | import org.json.JSONObject; 46 | import ru.elegramapi.www.Bot; 47 | import ru.elegramapi.www.Command; 48 | import ru.elegramapi.www.request.TRqGetUpdates; 49 | import ru.elegramapi.www.request.TRqPost; 50 | import ru.elegramapi.www.request.TRqSendMessage; 51 | import ru.elegramapi.www.request.TRqWithChatId; 52 | import ru.elegramapi.www.request.TRqWithOffset; 53 | import ru.elegramapi.www.request.TRqWithText; 54 | import ru.elegramapi.www.update.UpdDefault; 55 | 56 | /** 57 | * The default implementation of {@link Bot}. 58 | * 59 | * @since 0.0.0 60 | */ 61 | public class BtDefault implements Bot { 62 | 63 | /** 64 | * All commands. 65 | */ 66 | private final List commands; 67 | 68 | /** 69 | * The token. 70 | */ 71 | private final String token; 72 | 73 | /** 74 | * The processed updates. 75 | */ 76 | private final Set processed; 77 | 78 | /** 79 | * Read-write lock. 80 | */ 81 | private Thread thread; 82 | 83 | /** 84 | * Ctor. 85 | * 86 | * @param token The token 87 | * @param commands All custom commands 88 | */ 89 | public BtDefault(final String token, final Command... commands) { 90 | this.token = token; 91 | this.commands = new ListOf<>(commands); 92 | this.processed = new HashSet<>(0); 93 | this.thread = new Thread(); 94 | } 95 | 96 | @Override 97 | public final void start() throws IOException, InterruptedException { 98 | this.handleUpdates(); 99 | } 100 | 101 | @Override 102 | public final JsonResponse sendMessage(final long chat, final String text) throws IOException { 103 | return new TRqPost( 104 | new TRqWithChatId( 105 | new TRqWithText( 106 | new TRqSendMessage(this.token), 107 | text 108 | ), 109 | chat 110 | ) 111 | ).response(); 112 | } 113 | 114 | /** 115 | * Handles the updates. 116 | * 117 | * @throws InterruptedException Thread interrupted 118 | * @throws IOException When getting updates went wrong 119 | */ 120 | private void handleUpdates() throws InterruptedException, IOException { 121 | final BlockingQueue updates = new LinkedBlockingQueue<>(); 122 | this.updatingThread(updates); 123 | this.processUpdates(updates); 124 | } 125 | 126 | /** 127 | * Processing updates. 128 | * 129 | * @param updates The queue with updates 130 | * @throws InterruptedException When thread interrupted 131 | * @throws IOException When something went wrong 132 | */ 133 | private void processUpdates(final BlockingQueue updates) 134 | throws InterruptedException, IOException { 135 | while (true) { 136 | for (final Command command : this.commands) { 137 | command.act(new UpdDefault(updates.take()), this); 138 | } 139 | } 140 | } 141 | 142 | /** 143 | * Creates thread for handling updates. 144 | * 145 | * @param updates Queue with updates 146 | */ 147 | private void updatingThread(final BlockingQueue updates) { 148 | if (!this.thread.isAlive()) { 149 | this.thread = new Thread( 150 | () -> { 151 | while (!Thread.currentThread().isInterrupted()) { 152 | this.fillUpdates(updates); 153 | } 154 | } 155 | ); 156 | this.thread.start(); 157 | } 158 | } 159 | 160 | /** 161 | * Check new updates. 162 | * 163 | * @param accum Queue with updates 164 | */ 165 | private void fillUpdates(final BlockingQueue accum) { 166 | final AtomicInteger offset = new AtomicInteger(); 167 | this.putNewUpdates(accum, offset, this.updates(offset)); 168 | try { 169 | Thread.sleep(1500L); 170 | } catch (final InterruptedException ex) { 171 | Thread.currentThread().interrupt(); 172 | throw new IllegalStateException(ex); 173 | } 174 | } 175 | 176 | /** 177 | * Updates as json. 178 | * 179 | * @param offset The offset 180 | * @return The updates 181 | */ 182 | private JSONArray updates(final AtomicInteger offset) { 183 | try { 184 | return new JSONObject( 185 | new TRqWithOffset( 186 | new TRqGetUpdates(this.token), 187 | offset.get() 188 | ).response().body() 189 | ).getJSONArray("result"); 190 | } catch (final IOException ex) { 191 | throw new IllegalStateException("Error while getting updates", ex); 192 | } 193 | } 194 | 195 | /** 196 | * Iterating through updates with offset calculation. 197 | * 198 | * @param updates The updates queue 199 | * @param offset The offset for each update 200 | * @param server The data from server as JSON 201 | */ 202 | private void putNewUpdates( 203 | final BlockingQueue updates, 204 | final AtomicInteger offset, 205 | final Iterable server 206 | ) { 207 | for (final Object upd : server) { 208 | final int idx = new JSONObject(upd.toString()).getInt("update_id"); 209 | if (this.processed.contains((long) idx)) { 210 | continue; 211 | } 212 | this.processed.add((long) idx); 213 | offset.set(idx + 1); 214 | try { 215 | updates.put(new JSONObject(upd.toString())); 216 | } catch (final InterruptedException ex) { 217 | Thread.currentThread().interrupt(); 218 | throw new IllegalStateException("Interrupted while filling updates", ex); 219 | } 220 | } 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 4.0.0 27 | ru.l3r8y 28 | elegram-api 29 | jar 30 | The EO styled wrapper of Telegram bots api 31 | 1.1-SNAPSHOT 32 | elegram-api 33 | 34 | 35 | MIT 36 | https://github.com/l3r8yJ/elegram-api/blob/master/LICENSE.txt 37 | 38 | 39 | 40 | github 41 | https://github.com/l3r8yJ/elegram-api/issues 42 | 43 | 44 | scm:git:git@github.com:l3r8y/elegram-api.git 45 | scm:git:git@github.com:l3r8y/elegram-api.git 46 | https://github.com/l3r8yJ/elegram-api 47 | 48 | 49 | rultor 50 | https://www.rultor.com/s/elegram-api 51 | 52 | 53 | 54 | www.elegram-api.ru 55 | https://www.elegram-api.ru 56 | 57 | 58 | 59 | 60 | 1 61 | Ivanchuck Ivan 62 | clicker.heroes.acg@gmail.com 63 | 64 | Architect 65 | Developer 66 | 67 | +3 68 | 69 | 70 | 71 | 1.8 72 | ${project.java.version} 73 | ${project.java.version} 74 | UTF-8 75 | 5.9.3 76 | 0.55.0 77 | 1.20.1 78 | 2.2 79 | 20230227 80 | 0.22.0 81 | 0.22.0 82 | 2.39.1 83 | 2.1.1 84 | 1.1.4 85 | 3.5.0 86 | 0.8.8 87 | 0.1.8 88 | 2.0.7 89 | 3.11.0 90 | 3.0.0 91 | 3.5.1 92 | 0.24.1 93 | 1.6.12 94 | 0.8 95 | 3.1.0 96 | 97 | 98 | 99 | org.cactoos 100 | cactoos 101 | ${cactoos.version} 102 | 103 | 104 | javax.ws.rs 105 | javax.ws.rs-api 106 | ${javax.ws.rs-api.version} 107 | test 108 | 109 | 110 | org.glassfish.jersey.core 111 | jersey-common 112 | ${jersey-common.version} 113 | test 114 | 115 | 116 | 117 | javax.json 118 | javax.json-api 119 | ${javax.json-api.version} 120 | test 121 | 122 | 123 | com.jcabi 124 | jcabi-http 125 | ${jcabi.http.version} 126 | 127 | 128 | org.slf4j 129 | slf4j-jdk14 130 | ${slf4j-jdk14.version} 131 | runtime 132 | 133 | 134 | com.jcabi 135 | jcabi-log 136 | ${jcabi-log.version} 137 | 138 | 139 | org.json 140 | json 141 | ${json.version} 142 | 143 | 144 | org.junit.jupiter 145 | junit-jupiter-api 146 | ${junit.version} 147 | test 148 | 149 | 150 | org.hamcrest 151 | hamcrest 152 | ${hamcrest.version} 153 | test 154 | 155 | 156 | 157 | 158 | 159 | maven-javadoc-plugin 160 | ${maven-javadoc-plugin.version} 161 | 162 | ${project.java.version} 163 | 164 | 165 | 166 | maven-compiler-plugin 167 | ${maven-compiler-plugin.version} 168 | 169 | ${maven.compiler.source} 170 | ${maven.compiler.target} 171 | 172 | -Xpkginfo:always 173 | 174 | 175 | 176 | 177 | org.apache.maven.plugins 178 | maven-surefire-plugin 179 | ${maven-surefire-plugin.version} 180 | 181 | 182 | **/*Spec.* 183 | **/*Test.* 184 | 185 | 186 | 187 | 188 | maven-invoker-plugin 189 | ${maven-invoker-plugin.version} 190 | 191 | src/it/settings.xml 192 | verify 193 | true 194 | 195 | 196 | 197 | integration-test 198 | 199 | install 200 | run 201 | 202 | 203 | 204 | 205 | 206 | org.jacoco 207 | jacoco-maven-plugin 208 | ${jacoco-maven-plugin.version} 209 | 210 | 211 | 212 | prepare-agent 213 | 214 | 215 | 216 | report 217 | prepare-package 218 | 219 | report 220 | 221 | 222 | 223 | 224 | 225 | maven-deploy-plugin 226 | ${maven-deploy-plugin.version} 227 | 228 | 229 | default-deploy 230 | deploy 231 | 232 | deploy 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | qulice 242 | 243 | 244 | 245 | com.qulice 246 | qulice-maven-plugin 247 | ${qulice-maven-plugin.version} 248 | 249 | file:${basedir}/LICENSE.txt 250 | 251 | duplicatefinder:.* 252 | 253 | 254 | 255 | 256 | 257 | check 258 | 259 | 260 | 261 | 262 | 263 | com.github.volodya-lombrozo 264 | test-naming-conventions 265 | ${test-naming-conventions.version} 266 | 267 | 268 | 269 | check 270 | 271 | 272 | 273 | 274 | 275 | ru.l3r8y 276 | sa-tan 277 | 0.1.5 278 | 279 | 280 | 281 | search 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | --------------------------------------------------------------------------------