You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
3.3 KiB

11 years ago
package org.telegram;
import org.telegram.telegrambots.TelegramApiException;
import org.telegram.telegrambots.TelegramBotsApi;
import org.telegram.telegrambots.logging.BotLogger;
import org.telegram.telegrambots.logging.BotsFileHandler;
10 years ago
import org.telegram.updateshandlers.*;
import java.io.IOException;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
11 years ago
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Main class to create all bots
* @date 20 of June of 2015
*/
public class Main {
private static final String LOGTAG = "MAIN";
11 years ago
public static void main(String[] args) {
BotLogger.setLevel(Level.ALL);
BotLogger.registerLogger(new ConsoleHandler());
try {
BotLogger.registerLogger(new BotsFileHandler());
} catch (IOException e) {
BotLogger.severe("MAIN", e);
}
10 years ago
// default, start all sample bots in getUpdates mode
if (!BuildVars.useWebHook) {
TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
10 years ago
try {
telegramBotsApi.registerBot(new ChannelHandlers());
telegramBotsApi.registerBot(new DirectionsHandlers());
telegramBotsApi.registerBot(new RaeHandlers());
telegramBotsApi.registerBot(new WeatherHandlers());
telegramBotsApi.registerBot(new TransifexHandlers());
telegramBotsApi.registerBot(new FilesHandlers());
10 years ago
} catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e);
}
// Filled a path to a pem file ? looks like you're going for the self signed option then, invoke with store and pem file to supply.
// check https://core.telegram.org/bots/self-signed#java-keystore for generating a keypair in store and exporting the pem.
// dont forget to split the pem bundle (begin/end), use only the public key as input!
} else if (!BuildVars.pathToCertificatePublicKey.isEmpty()) {
try {
TelegramBotsApi telegramBotsSelfWebhookApi = new TelegramBotsApi(BuildVars.pathToCertificateStore, BuildVars.certificateStorePassword, BuildVars.EXTERNALWEBHOOKURL, BuildVars.INTERNALWEBHOOKURL,BuildVars.pathToCertificatePublicKey);
telegramBotsSelfWebhookApi.registerBot(new webHookExampleHandlers());
} catch (Exception e) {
BotLogger.error(LOGTAG, e);
}
} else {
// Non self signed, make sure you've added private/public and if needed intermediate to your cert-store.
// Coming from a set of pem files here's one way to do it:
// openssl pkcs12 -export -in public.pem -inkey private.pem > keypair.p12
// keytool -importkeystore -srckeystore keypair.p12 -destkeystore server.jks -srcstoretype pkcs12
// have (an) intermediate(s) to supply? first: cat public.pem intermediate.pem > set.pem (use set.pem as -in)
try {
TelegramBotsApi telegramBotsWebhookApi = new TelegramBotsApi(BuildVars.pathToCertificateStore, BuildVars.certificateStorePassword, BuildVars.EXTERNALWEBHOOKURL, BuildVars.INTERNALWEBHOOKURL);
telegramBotsWebhookApi.registerBot(new webHookExampleHandlers());
} catch (Exception e) {
BotLogger.error(LOGTAG, e);
}
}
11 years ago
}
}