本文整理汇总了Java中com.pengrad.telegrambot.TelegramBot类的典型用法代码示例。如果您正苦于以下问题:Java TelegramBot类的具体用法?Java TelegramBot怎么用?Java TelegramBot使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TelegramBot类属于com.pengrad.telegrambot包,在下文中一共展示了TelegramBot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executarBot
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
/**
* Executa a inicializa��o do bot e realiza o 'polling' de mensagens enviadas
*/
public void executarBot() {
TelegramBot bot = TelegramBotAdapter.build(TOKEN_ACESSO);
int m = 0;
while (true) {
List<Update> updates = bot.execute(new GetUpdates().limit(100).offset(m)).updates();
for (Update update : updates) {
m = update.updateId() + 1;
String mensagemRetorno = "";
if (update.message() != null) {
bot.execute(new SendChatAction(update.message().chat().id(), ChatAction.typing.name()));
try {
mensagemRetorno = tratarMensagemBot(update);
} catch (Exception e) {
mensagemRetorno = "Desculpe, n�o entendi... digite /ajuda para obter a lista de comandos conhecidos.";
}
bot.execute(new SendMessage(update.message().chat().id(), mensagemRetorno.toString()));
}
}
}
}
示例2: apply
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
@Override
public void apply(final SendMessage sendMessage) {
final ImageSendPayload imageSendPayload = sendMessage.getPayloadWithType(ImageSendPayload.class);
final String title = imageSendPayload.getTitle();
final String imageUrl = imageSendPayload.getImageUrl();
final String recipient = sendMessage.getRecipient().getId();
final SendPhoto sendPhotoTelegram = new SendPhoto(recipient, imageUrl);
if (!Strings.isBlank(title)) {
sendPhotoTelegram.caption(title);
}
LOG.info("sending image {} to recipient {}", sendPhotoTelegram, recipient);
final TelegramBot client = provideTelegramBot(sendMessage);
client.execute(sendPhotoTelegram);
}
示例3: apply
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
@Override
public void apply(final SendMessage sendMessage) {
final VideoSendPayload videoSendPayload = sendMessage.getPayloadWithType(VideoSendPayload.class);
final String title = videoSendPayload.getTitle();
final String videoUrl = videoSendPayload.getVideoUrl();
final String recipient = sendMessage.getRecipient().getId();
final SendVideo sendVideoTelegram = new SendVideo(recipient, videoUrl);
if (!Strings.isBlank(title)) {
sendVideoTelegram.caption(title);
}
LOG.info("sending video {} to recipient {}", sendVideoTelegram, recipient);
final TelegramBot client = provideTelegramBot(sendMessage);
client.execute(sendVideoTelegram);
}
示例4: reloadIfNeeded
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
/**
* Reload bot if settings changed
* @param newSettings updated user settings
*/
public synchronized void reloadIfNeeded(@NotNull TelegramSettings newSettings) {
if (Objects.equals(newSettings, settings)) {
LOG.debug("Telegram bot token settings has not changed");
return;
}
LOG.debug("New telegram bot token is received: " +
StringUtil.truncateStringValueWithDotsAtEnd(newSettings.getBotToken(), 6));
this.settings = newSettings;
cleanupBot();
if (settings.getBotToken() != null && !settings.isPaused()) {
TelegramBot newBot = createBot(settings);
addUpdatesListener(newBot);
bot = newBot;
}
}
示例5: createBot
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
private TelegramBot createBot(@NotNull TelegramSettings settings) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
if (settings.isUseProxy()) {
builder.proxy(new Proxy(Proxy.Type.HTTP,
new InetSocketAddress(settings.getProxyServer(), settings.getProxyPort())));
if (!StringUtils.isEmpty(settings.getProxyUsername()) &&
!StringUtils.isEmpty(settings.getProxyPassword())) {
builder.proxyAuthenticator((route, response) -> {
String credential =
Credentials.basic(settings.getProxyUsername(), settings.getProxyPassword());
return response.request().newBuilder()
.header("Proxy-Authorization", credential)
.build();
});
}
}
return TelegramBotAdapter.buildCustom(settings.getBotToken(), builder.build());
}
示例6: sendSchedule
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
@Override
public void sendSchedule(TelegramBot bot, Message currentMessage, int day) {
TimeUnit t = TimeUnit.MILLISECONDS;
long daySeconds = t.convert(1L, TimeUnit.DAYS);
DateFormat.DATE_FORMAT.applyPattern(DateFormat.DATE_FORMAT_PATTERN);
Date date = new Date(t.convert(currentMessage.date(), TimeUnit.SECONDS) + daySeconds * day);
DayResponse groupSchedule = GetModels.getModels(Api.groupSchedule(settings.get(3)) + DateFormat.DATE_FORMAT.format(date),
DayResponse.class);
if(currentMessage.text().startsWith("/week")){
for (Day daySchedule : groupSchedule.getDays()) {
bot.sendMessage(currentMessage.chat().id(), daySchedule.toString(), ParseMode.Markdown, null, null, null);
}
return;
}
String sсhedule = groupSchedule.getDays().get(0).toString();
bot.sendMessage(currentMessage.chat().id(), sсhedule.toString(), ParseMode.Markdown, null, null, null);
}
示例7: sendSchedule
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
@Override
public void sendSchedule(TelegramBot bot, Message currentMessage, int day) {
TimeUnit t = TimeUnit.MILLISECONDS;
long daySeconds = t.convert(1L, TimeUnit.DAYS);
DateFormat.DATE_FORMAT.applyPattern(DateFormat.DATE_FORMAT_PATTERN);
Date date = new Date(t.convert(currentMessage.date(), TimeUnit.SECONDS) + daySeconds * day);
DayResponse teacherSchedule = GetModels
.getModels(Api.teacherSchedule(teacherId) + DateFormat.DATE_FORMAT.format(date), DayResponse.class);
if(currentMessage.text().startsWith("/week")){
for (Day daySchedule : teacherSchedule.getDays()) {
bot.sendMessage(currentMessage.chat().id(), daySchedule.toString(), ParseMode.Markdown, null, null, null);
}
return;
}
String sсhedule = teacherSchedule.getDays().get(0).toString();
bot.sendMessage(currentMessage.chat().id(), sсhedule.toString(), ParseMode.Markdown, null, null, null);
}
示例8: createBot
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
public static TelegramBot createBot(ConfigData configData)
{
TelegramBot bot = null;
if(configData.proxyConfig.enableProxy)
{
bot = TelegramBotAdapter.buildCustom(configData.telegramBotToken,setProxy(configData));
}
else
{
bot = TelegramBotAdapter.build(configData.telegramBotToken);
}
return bot;
}
示例9: main
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args)
{
File configFile = new File("./config.json");
ConfigData configData = new ConfigData();
try
{
if(configFile.exists())
{
configData = config.ReadConfig.readConfig(configFile);
}
else
{
configFile.createNewFile();
config.CreateConfigs.createConfigs(configFile);
System.out.println("没有合适的配置文件,已创建空配置文件,请打开config.json进行配置。");
System.exit(0);
}
}
catch(IOException e)
{
e.printStackTrace();
}
TelegramBot bot = telegrambot.Initializer.createBot(configData);
telegrambot.TelegramRunner telegramThread = new TelegramRunner(bot, configData);
qqbot.QQRunner qqThread = new QQRunner(configData);
telegramThread.run();
qqThread.run();
PluginsLoader pluginsLoader = new PluginsLoader(configData);
pluginsLoader.run();
}
示例10: init
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
@Inject
protected void init() {
final String webhookUrl = telegramConfigService.getWebhookUrl((ReceiveMessage) null);
if (Strings.isBlank(webhookUrl)) {
} else {
final SetWebhook request = new SetWebhook().url(webhookUrl);
final TelegramBot bot = provideTelegramBot();
bot.execute(request);
}
}
示例11: getFileUrl
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
protected String getFileUrl(final ReceiveMessage receiveMessage, final String fileId) {
final TelegramBot bot = provideTelegramBot(receiveMessage);
final GetFile getFile = new GetFile(fileId);
final GetFileResponse response = bot.execute(getFile);
final File file = response.file();
final String url = bot.getFullFilePath(file);
return url;
}
示例12: sendPhotoElement
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
protected void sendPhotoElement(final SendMessage sendMessage, final String recipient,
final ListSendElement listSendElement) {
final SendPhoto sendPhotoTelegram = new SendPhoto(recipient, listSendElement.getImageUrl());
final String title = listSendElement.getTitle();
if (!Strings.isBlank(title)) {
sendPhotoTelegram.caption(title);
}
LOG.info("sending image {} to recipient {}", sendPhotoTelegram, recipient);
final TelegramBot client = provideTelegramBot(sendMessage);
client.execute(sendPhotoTelegram);
}
示例13: requestDescription
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
@Nullable
public BotInfo requestDescription(@NotNull TelegramSettings settings) {
TelegramBot bot = createBot(settings);
GetMeResponse response = bot.execute(new GetMe());
User user = response.user();
if (user == null) {
return null;
}
return new BotInfo(user.firstName(), user.username());
}
示例14: addUpdatesListener
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
private void addUpdatesListener(TelegramBot bot) {
bot.setUpdatesListener(updates -> {
for (Update update: updates) {
Message message = update.message();
Long chatId = message.chat().id();
SendMessage msg = new SendMessage(chatId,
"Hello! Your chat id is '" + chatId + "'.\n" +
"If you want to receive notifications about Teamcity events " +
"please add this chat id in your Teamcity settings");
bot.execute(msg);
}
return UpdatesListener.CONFIRMED_UPDATES_ALL;
});
}
示例15: start
import com.pengrad.telegrambot.TelegramBot; //导入依赖的package包/类
public void start(TelegramBot bot, UpdatesListener listener, GetUpdates request) {
this.bot = bot;
this.listener = listener;
getUpdates(request);
}