• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TelegramBot类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中pro.zackpollard.telegrambot.api.TelegramBot的典型用法代码示例。如果您正苦于以下问题:Java TelegramBot类的具体用法?Java TelegramBot怎么用?Java TelegramBot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TelegramBot类属于pro.zackpollard.telegrambot.api包,在下文中一共展示了TelegramBot类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: ReddigramBot

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
ReddigramBot() throws Exception {
    timer = new Timer();
    config = BotConfig.configFromFile(new File("config.json"));
    dataFile = DataFile.load(this);
    client = new RedditClient(UserAgent.of("server", "xyz.mkotb.reddigram", "1.0", config.redditUsername()));
    telegramBot = TelegramBot.login(config.botApiKey());
    liveManager = new LiveManager(this);

    telegramBot.getEventsManager().register(new InlineListener(this));
    telegramBot.getEventsManager().register(new CommandListener(this));
    telegramBot.startUpdates(true);
    log("Successfully logged in");

    timer.scheduleAtFixedRate(new OAuthTask(this), 0L, 3500000L); // every 58 minutes reauth.
    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            if (dataFile != null) {
                dataFile.save();
            }
        }
    }, 0L, 600000L); // every 10m save data file
}
 
开发者ID:mkotb,项目名称:Reddigram,代码行数:24,代码来源:ReddigramBot.java


示例2: EchoBot

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
public EchoBot() {

        //This returns a logged in TelegramBot instance or null if the API key was invalid.
        telegramBot = TelegramBot.login(API_KEY);
        //This registers the EchoListener Listener to this bot.
        telegramBot.getEventsManager().register(new EchoListener(telegramBot));
        //This method starts the retrieval of updates.
        //The boolean it accepts is to specify whether to retrieve messages
        //which were sent before the bot was started but after the bot was last turned off.
        telegramBot.startUpdates(false);

        //The following while(true) loop is simply for keeping the java application alive.
        //You can do this however you like, but none of the above methods are blocking and
        //so without this code the bot would simply boot then exit.
        while (true) {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API-Examples,代码行数:23,代码来源:EchoBot.java


示例3: InlineTranslationBot

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
public InlineTranslationBot() {

        //This returns a logged in TelegramBot instance or null if the API key was invalid.
        telegramBot = TelegramBot.login(API_KEY);
        //This registers the FormattingListener Listener to this bot.
        telegramBot.getEventsManager().register(new InlineTranslationListener(telegramBot));
        //This method starts the retrieval of updates.
        //The boolean it accepts is to specify whether to retrieve messages
        //which were sent before the bot was started but after the bot was last turned off.
        telegramBot.startUpdates(false);

        //The following while(true) loop is simply for keeping the java application alive.
        //You can do this however you like, but none of the above methods are blocking and
        //so without this code the bot would simply boot then exit.
        while (true) {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API-Examples,代码行数:23,代码来源:InlineTranslationBot.java


示例4: InlineSpoilerBot

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
public InlineSpoilerBot() {

        instance = this;

        //This returns a logged in TelegramBot instance or null if the API key was invalid.
        telegramBot = TelegramBot.login(API_KEY);
        //This registers the SpoilerListener Listener to this bot.
        initSpoilerManager();
        telegramBot.getEventsManager().register(listener);
        //This method starts the retrieval of updates.
        //The boolean it accepts is to specify whether to retrieve messages
        //which were sent before the bot was started but after the bot was last turned off.
        telegramBot.startUpdates(false);

        //The following while(true) loop is simply for keeping the java application alive.
        //You can do this however you like, but none of the above methods are blocking and
        //so without this code the bot would simply boot then exit.
        while (true) {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API-Examples,代码行数:26,代码来源:InlineSpoilerBot.java


示例5: FormattingBot

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
public FormattingBot() {

        //This returns a logged in TelegramBot instance or null if the API key was invalid.
        telegramBot = TelegramBot.login(API_KEY);
        //This registers the FormattingListener Listener to this bot.
        telegramBot.getEventsManager().register(new FormattingListener(telegramBot));
        //This method starts the retrieval of updates.
        //The boolean it accepts is to specify whether to retrieve messages
        //which were sent before the bot was started but after the bot was last turned off.
        telegramBot.startUpdates(false);

        //The following while(true) loop is simply for keeping the java application alive.
        //You can do this however you like, but none of the above methods are blocking and
        //so without this code the bot would simply boot then exit.
        while (true) {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API-Examples,代码行数:23,代码来源:FormattingBot.java


示例6: processReplyContent

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
/**
 * This does generic processing of ReplyingOptions objects when sending a request to the API
 *
 * @param multipartBody     The MultipartBody that the ReplyingOptions content should be appended to
 * @param replyingOptions   The ReplyingOptions that were used in this request
 */
public static void processReplyContent(MultipartBody multipartBody, ReplyingOptions replyingOptions) {

    if (replyingOptions.getReplyTo() != 0)
        multipartBody.field("reply_to_message_id", String.valueOf(replyingOptions.getReplyTo()), "application/json; charset=utf8;");
    if (replyingOptions.getReplyMarkup() != null) {

        switch (replyingOptions.getReplyMarkup().getType()) {

            case FORCE_REPLY:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ForceReply.class), "application/json; charset=utf8;");
                break;
            case KEYBOARD_HIDE:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ReplyKeyboardHide.class), "application/json; charset=utf8;");
                break;
            case KEYBOARD_REMOVE:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ReplyKeyboardRemove.class), "application/json; charset=utf8;");
                break;
            case KEYBOARD_MARKUP:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ReplyKeyboardMarkup.class), "application/json; charset=utf8;");
                break;
            case INLINE_KEYBOARD_MARKUP:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), InlineKeyboardMarkup.class), "application/json; charset=utf8;");
                break;
        }
    }
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:33,代码来源:Utils.java


示例7: MessageImpl

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
private MessageImpl(JSONObject jsonObject, TelegramBot telegramBot) {

        if (!jsonObject.isNull("result")) jsonObject = jsonObject.getJSONObject("result");

        jsonMessage = jsonObject;

        message_id = jsonObject.getInt("message_id");
        from = UserImpl.createUser(jsonObject.optJSONObject("from"));
        date = jsonObject.getLong("date");
        chat = ChatImpl.createChat(jsonObject.getJSONObject("chat"), telegramBot);
        forward_from = UserImpl.createUser(jsonObject.optJSONObject("forward_from"));
        forward_from_chat = ChatImpl.createChat(jsonObject.optJSONObject("forward_from_chat"), telegramBot);
        forward_from_message_id = jsonObject.optInt("forward_from_message_id");
        forward_date = jsonObject.optLong("forward_date");
        reply_to_message = MessageImpl.createMessage(jsonObject.optJSONObject("reply_to_message"), telegramBot);
        edit_date = jsonObject.optLong("edit_date");
        content = ContentImpl.createContent(jsonObject, telegramBot);

        this.telegramBot = telegramBot;
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:21,代码来源:MessageImpl.java


示例8: createChat

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
public static Chat createChat(JSONObject jsonObject, TelegramBot telegramBot) {

        if(jsonObject != null) {

            String chatType = jsonObject.getString("type");

            switch (chatType) {

                case "private":
                    return IndividualChatImpl.createIndividualChat(jsonObject, telegramBot);
                case "group":
                    return GroupChatImpl.createGroupChat(jsonObject, telegramBot);
                case "channel":
                    return ChannelChatImpl.createChannelChat(jsonObject, telegramBot);
                case "supergroup":
                    return SuperGroupChatImpl.createSuperGroupChat(jsonObject, telegramBot);
                default:
                    System.err.println("An invalid chat type was provided when creating a chat object. Chat type " + chatType + " was provided. Report this to @zackpollard.");
            }
        }

        return null;
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:24,代码来源:ChatImpl.java


示例9: getFileDownloadLink

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
/**
 * Gets the download link for this file
 *
 * @param telegramBot The TelegramBot instance that relates to this file
 *
 * @return The URL to download the file in String form
 */
default String getFileDownloadLink(TelegramBot telegramBot) {

    JSONObject jsonObject = null;

    try {
        jsonObject = Unirest.post(telegramBot.getBotAPIUrl() + "getFile")
                .field("file_id", getFileId(), "application/json; charset=utf8;")
                .asJson().getBody().getObject();
    } catch (UnirestException e) {
        e.printStackTrace();
    }

    if (jsonObject != null) {

        if (jsonObject.getBoolean("ok")) {

            return "https://api.telegram.org/file/bot" + telegramBot.getAuthToken() + "/" + jsonObject.getJSONObject("result").getString("file_path");
        }
    }

    return null;
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:30,代码来源:File.java


示例10: downloadFile

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
/**
 * Downloads the file to a set location on disk
 *
 * @param telegramBot       The TelegramBot instance that relates to this file
 * @param downloadLocation  A File object pointing to the location where you want to download the file
 *
 * @return A File object that points to the downloaded file
 */
default java.io.File downloadFile(TelegramBot telegramBot, java.io.File downloadLocation) {

    String downloadLink = getFileDownloadLink(telegramBot);

    if (downloadLink != null) {

        try {
            FileUtils.copyURLToFile(new URL(downloadLink), downloadLocation);
        } catch (IOException e) {

            System.err.println("The file download failed due to the provided URL being malformed in some way. Provided URL was " + downloadLink);
        }
    }

    return downloadLocation;
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:25,代码来源:File.java


示例11: RemindMeBot

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
private RemindMeBot(String key) {
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    instance = this;
    this.bot = TelegramBot.login(key);
    bot.getEventsManager().register(new RemindMeBotListener());
    bot.startUpdates(false);
    storageHook = new StorageHook();
    reminderManager = new ReminderManager();

    //Save reminder map on shutdown to ensure persistence of reminders
    Runtime.getRuntime().addShutdownHook(new Thread(storageHook::save));

    this.debug("Bot started!");
}
 
开发者ID:bo0tzz,项目名称:RemindMeBot,代码行数:15,代码来源:RemindMeBot.java


示例12: WhatIsBot

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
public WhatIsBot(String key) {
    System.out.println("Initialising bot");
    bot = TelegramBot.login(key);
    if (bot == null) {
        System.out.println("Failed to login! Faulty API key?");
        System.exit(1);
    }
    System.out.println("Registering events");
    bot.getEventsManager().register(new WhatIsBotListener(this));
    bot.startUpdates(false);
    System.out.println("Bot initialised!");
}
 
开发者ID:bo0tzz,项目名称:WhatIsBot,代码行数:13,代码来源:WhatIsBot.java


示例13: Conversation

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
private Conversation(TelegramBot bot, Map<String, Object> sessionData, Chat forWhom, boolean silent,
                    boolean disableGlobalEvents, List<ConversationPrompt> prompts,
                     Predicate<User> userPredicate, boolean repliesOnly,
                     BiConsumer<Conversation, ConversationContext> endCallback,
                     BiPredicate<ConversationContext, Content> endPredicate,
                     long timeout, SendableMessage timeoutMessage) {
    this.forWhom = forWhom;
    this.context = new ConversationContext(this, bot, sessionData);
    this.currentPrompt = prompts.get(promptIndex);
    this.prompts = Collections.unmodifiableList(prompts);
    this.silent = silent;
    this.disableGlobalEvents = disableGlobalEvents;
    this.userPredicate = (userPredicate == null) ? (user) -> true : userPredicate;
    this.repliesOnly = repliesOnly;
    this.endCallback = endCallback;
    this.endPredicate = endPredicate;

    if (timeout > 0) {
        TIMER.schedule(new TimerTask() {
            @Override
            public void run() {
                if (isVirgin()) {
                    if (timeoutMessage != null) {
                        sendMessage(timeoutMessage);
                    }

                    end();
                }
            }
        }, TimeUnit.SECONDS.toMillis(timeout));
    }
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:33,代码来源:Conversation.java


示例14: ConversationRegistryImpl

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
private ConversationRegistryImpl(TelegramBot bot) {
    bot.getEventsManager().register(new Listener() {
        @Override
        @Event.Handler(ignoreCancelled = true, priority = Event.Priority.LOWEST)
        public void onMessageReceived(MessageReceivedEvent event) {
            if (processMessage(event.getMessage())) {
                event.setCancelled(true);
            }
        }
    });
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:12,代码来源:ConversationRegistryImpl.java


示例15: InlineMenuRegistryImpl

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
private InlineMenuRegistryImpl(TelegramBot bot) {
    bot.getEventsManager().register(new Listener() {
        @Event.Handler(ignoreCancelled = true, priority = Event.Priority.LOWEST)
        @Override
        public void onCallbackQueryReceivedEvent(CallbackQueryReceivedEvent event) {
            if (process(event.getCallbackQuery())) {
                event.setCancelled(true);
            }
        }
    });
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:12,代码来源:InlineMenuRegistryImpl.java


示例16: createUserProfilePhotos

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
public static UserProfilePhotos createUserProfilePhotos(long user_id, TelegramBot telegramBot) {

        try {
            JSONObject json = Unirest.post(telegramBot.getBotAPIUrl() + "getUserProfilePhotos")
                    .queryString("user_id", user_id).asJson().getBody().getObject();
            if(json.getBoolean("ok")) {
                return new UserProfilePhotosImpl(json.getJSONObject("result"));
            }
        } catch (UnirestException e) {
            e.printStackTrace();
        }

        return null;
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:15,代码来源:UserProfilePhotosImpl.java


示例17: CallbackQueryImpl

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
protected CallbackQueryImpl(JSONObject jsonObject, TelegramBot telegramBot) {

        this.id = jsonObject.getString("id");
        this.from = UserImpl.createUser(jsonObject.getJSONObject("from"));
        this.data = jsonObject.optString("data");
        this.chatInstance = jsonObject.getString("chat_instance");

        this.jsonCallbackQuery = jsonObject;

        this.telegramBot = telegramBot;
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:12,代码来源:CallbackQueryImpl.java


示例18: SuperGroupChatImpl

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
private SuperGroupChatImpl(JSONObject jsonObject, TelegramBot telegramBot) {

        this.id = jsonObject.getLong("id");
        this.username = "@" + jsonObject.optString("username");
        this.title = jsonObject.getString("title");
        this.allMembersAreAdministrators = jsonObject.optBoolean("all_members_are_administrators");
        this.telegramBot = telegramBot;
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:9,代码来源:SuperGroupChatImpl.java


示例19: GroupChatImpl

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
private GroupChatImpl(JSONObject jsonObject, TelegramBot telegramBot) {

        this.id = jsonObject.getInt("id");
        this.title = jsonObject.getString("title");
        this.allMembersAreAdministrators = jsonObject.optBoolean("all_members_are_administrators");
        this.telegramBot = telegramBot;
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:8,代码来源:GroupChatImpl.java


示例20: InputFile

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
/**
 * Create an InputFile object based on an external URL to be sent within a SendableMessage
 *
 * @param url The URL of the file you want this InputFile to point to
 */
public InputFile(URL url) {

    File file = TelegramBot.getFileManager().getFile(url);
    String extension = null;
    if (file == null) {
        try {
            String stringifiedUrl = url.toExternalForm();
            HttpResponse<InputStream> response = Unirest.get(stringifiedUrl).asBinary();
            extension = FileExtension.getByMimeType(response.getHeaders().getFirst("content-type"));
            if (extension == null) {
                extension = stringifiedUrl.substring(stringifiedUrl.lastIndexOf('.') + 1);

                int variableIndex = extension.indexOf('?');
                if (variableIndex > 0) extension = extension.substring(0, variableIndex);

                if (extension.length() > 4) {
                    extension = null; // Default to .tmp if there was no valid extension
                }
            }
            file = File.createTempFile("jtb-" + System.currentTimeMillis(), "." + extension, FileManager.getTemporaryFolder());
            file.deleteOnExit();
            TelegramBot.getFileManager().cacheUrl(url, file);
            Files.copy(response.getRawBody(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
        } catch (UnirestException | IOException ex) {
            ex.printStackTrace();
        }
    }
    this.fileName = FilenameUtils.getBaseName(url.toString()) + "." + extension;
    this.file = file;
    this.fileID = TelegramBot.getFileManager().getFileID(file);
    this.inputStream = null;
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:38,代码来源:InputFile.java



注:本文中的pro.zackpollard.telegrambot.api.TelegramBot类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TableState类代码示例发布时间:2022-05-22
下一篇:
Java InnerClasses类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap