Java telegram bot api github

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Getting Started

  • Users guide
    • Getting Started
    • Errors Handling
    • Using HTTP Proxy
    • FAQ
    • Handling Bot Tokens
    • Understanding the Library
    • Simple Example
    • Hello Ability
    • Using Replies
    • Ability Toggle
    • State Machines
    • Database Handling
    • Ability Extensions
    • Bot Testing
    • Bot Recovery
    • Advanced
    • Additional Examples
    • How To Update
    Clone this wiki locally

    So, you’d like to create your own Telegram bot with TelegramBots? Then Let’s get You started quickly.

    First you need to acquire the library and add it to your project. There are several ways to do this:

      If you use Maven, Gradle, etc; you should be able to import the dependency directly from Maven Central Repository. For example:
      With Maven:

    dependency> groupId>org.telegramgroupId> artifactId>telegrambotsartifactId> version>6.7.0version> dependency>
    implementation 'org.telegram:telegrambots:6.7.0'

    Now that you have the library, you can start coding. There are few steps to follow, in this tutorial (for the sake of simplicity), we are going to build a Long Polling Bot:

      Creating your actual bot: The class must extends TelegramLongPollingBot and implement necessary methods:

    public class MyAmazingBot extends TelegramLongPollingBot < @Override public void onUpdateReceived(Update update) < // TODO > @Override public String getBotUsername() < // TODO return null; > @Override public String getBotToken() < // TODO return null; > >
    • getBotUsername() : This method must always return your Bot username. May look like:
    @Override public String getBotUsername() < return "myamazingbot"; >
    @Override public String getBotToken() < return "123456789:qwertyuioplkjhgfdsazxcvbnm"; >
    @Override public void onUpdateReceived(Update update) < // We check if the update has a message and the message has text if (update.hasMessage() && update.getMessage().hasText()) < SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields message.setChatId(update.getMessage().getChatId().toString()); message.setText(update.getMessage().getText()); try < execute(message); // Call method to send the message > catch (TelegramApiException e) < e.printStackTrace(); > > >
    public class Main < public static void main(String[] args) < // TODO Instantiate Telegram Bots API // TODO Register our bot > >
    • Instantiate Telegram Bots API: Easy as well, just create a new instance. Remember that a single instance can handle different bots but each bot can run only once (Telegram doesn’t support concurrent calls to GetUpdates ):
    public class Main < public static void main(String[] args) < // You can use your own BotSession implementation if needed. TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class); // TODO Register our bot > >
    public class Main < public static void main(String[] args) < try < TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class); botsApi.registerBot(new MyAmazingBot()); > catch (TelegramApiException e) < e.printStackTrace(); > > >

    Источник

    Saved searches

    Use saved searches to filter your results more quickly

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

    Java library to create bots using Telegram Bots API

    License

    rubenlagus/TelegramBots

    This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

    Name already in use

    A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

    Sign In Required

    Please sign in to use Codespaces.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching Xcode

    If nothing happens, download Xcode and try again.

    Launching Visual Studio Code

    Your codespace will open once ready.

    There was a problem preparing your codespace, please try again.

    Latest commit

    Git stats

    Files

    Failed to load latest commit information.

    README.md

    Telegram Bot Java Library

    A simple to use library to create Telegram Bots in Java

    Feel free to fork this project, work on it and then make a pull request against DEV branch. Most of the times I will accept them if they add something valuable to the code.

    Please, DO NOT PUSH ANY TOKEN OR API KEY, I will never accept a pull request with that content.

    Both ways are supported, but I recommend long polling method.

    Just import add the library to your project with one of these options:

    dependency> groupId>org.telegramgroupId> artifactId>telegrambotsartifactId> version>6.7.0version> dependency>
    implementation 'org.telegram:telegrambots:6.7.0'

    In order to use Long Polling mode, just create your own bot extending org.telegram.telegrambots.bots.TelegramLongPollingBot .

    If you like to use Webhook, extend org.telegram.telegrambots.bots.TelegramWebhookBot

    Once done, you just need to create a org.telegram.telegrambots.meta.TelegramBotsApi and register your bots:

    // Example taken from https://github.com/rubenlagus/TelegramBotsExample public class Main < public static void main(String[] args) < try < TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class); telegramBotsApi.registerBot(new ChannelHandlers()); telegramBotsApi.registerBot(new DirectionsHandlers()); telegramBotsApi.registerBot(new RaeHandlers()); telegramBotsApi.registerBot(new WeatherHandlers()); telegramBotsApi.registerBot(new TransifexHandlers()); telegramBotsApi.registerBot(new FilesHandlers()); > catch (TelegramApiException e) < e.printStackTrace(); > > >

    For detailed explanation, visite our How To (thanks Clevero)

    Open them and send them /help command to get some information about their capabilities:

    You can see code for those bots at TelegramBotsExample project.

    This library use Telegram bot API, you can find more information following the link.

    Feel free to create issues here as you need or join the chat

    Copyright (c) 2016 Ruben Bermudez

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the «Software»), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED «AS IS», WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    About

    Java library to create bots using Telegram Bots API

    Источник

    Saved searches

    Use saved searches to filter your results more quickly

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

    License

    JavaTelegramBot-API/JavaTelegramBot-API

    This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

    Name already in use

    A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

    Sign In Required

    Please sign in to use Codespaces.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching Xcode

    If nothing happens, download Xcode and try again.

    Launching Visual Studio Code

    Your codespace will open once ready.

    There was a problem preparing your codespace, please try again.

    Latest commit

    Git stats

    Files

    Failed to load latest commit information.

    README.md

    This is a Telegram Bot API for Java. At the time of writing it supports all the features of the HTTP API and follows the same specification. This is a work in progress and currently has very minimal error handling and testing. Any methods or functionality outside of pro.zackpollard.telegrambot.api.internal package should remain as they are currently and should work as expected, anything inside the internal package is not guaranteed to work as expected and may yield unexpected results if used in a way that is not intended.

    Telegram Channel for this API available at https://telegram.me/javatelegrambotapi
    Please join this channel for information about updates to this bot.
    You can also contact me at https://telegram.me/zackpollard
    If you need help in Persian(فارسی) you can contact https://telegram.me/aaomidi

    Source is stored on GitLab and mirrored to Github

    You can find fully working examples of bots in the following repository
    https://github.com/zackpollard/JavaTelegramBot-API-Examples

    The following is a simple overview of how the API works as a kind of quick start guide:

    //Main Class public class MyBot < public MyBot() < TelegramBot telegramBot = TelegramBot.login("APIKey"); //The API key was invalid, an error will have also been printed into the console. if(telegramBot == null) System.exit(-1); telegramBot.getEventsManager().register(new MyListener()); //This will tell the API to start polling the servers for updates //If you specify true as the argument you will receive any previous messages before the bot started. //If you specify false the API will discard any messages from before the bot was started. telegramBot.startUpdates(false); //Thread would die, do something to keep it alive. > > //Listener class public class MyListener implements Listener < public void onTextMessageReceived(TextMessageReceivedEvent event) < event.getChat().sendMessage(SendableTextMessage.builder().message("You sent me a text based message!").replyTo(event.getMessage()).build(), telegramBot); > >

    The API is available on Github Package Registry.

    Maven is used for dependency management and deployment.

    dependencies> dependency> groupId>pro.zackpollard.telegrambot.apigroupId> artifactId>jtelegram-botapiartifactId> version>1.7.2version> dependency> dependencies>

    The following is required temporarily as github package registry can’t be used without authentication, please follow the instructions on the following issue: #93 (comment)

    This project is licensed under the GPLv3 licence.

    Источник

    Читайте также:  Parameters meaning in java
Оцените статью