diff --git a/BotAPi.iml b/BotAPi.iml
index f5dc32a..827dbc7 100644
--- a/BotAPi.iml
+++ b/BotAPi.iml
@@ -11,7 +11,7 @@
-
+
diff --git a/pom.xml b/pom.xml
index 8037e8a..06f40ed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
UTF-8
UTF-8
4.5.2
- v2.3.3.2-alpha-2
+ v2.3.3.2
20160212
5.1.39
diff --git a/src/main/java/org/telegram/BotConfig.java b/src/main/java/org/telegram/BotConfig.java
index 9f56e8e..353e876 100644
--- a/src/main/java/org/telegram/BotConfig.java
+++ b/src/main/java/org/telegram/BotConfig.java
@@ -19,4 +19,6 @@ public class BotConfig {
public static final String USERNAMECHANNEL = "channelupdatesbot";
public static final String TOKENRAE = "";
public static final String USERNAMERAE = "raebot";
+ public static final String TOKENWEBHOOK = "";
+ public static final String USERNAMEWEBHOOK = "webhooksamplebot";
}
diff --git a/src/main/java/org/telegram/BuildVars.java b/src/main/java/org/telegram/BuildVars.java
index 9a973a0..3fc237f 100644
--- a/src/main/java/org/telegram/BuildVars.java
+++ b/src/main/java/org/telegram/BuildVars.java
@@ -6,14 +6,16 @@ package org.telegram;
* @brief Custom build vars FILL EVERYTHING CORRECTLY
* @date 20 of June of 2015
*/
+
public class BuildVars {
public static final Boolean debug = true;
- public static final Boolean useWebHook = true;
+ public static final Boolean useWebHook = false;
public static final int PORT = 8443;
- public static final String EXTERNALWEBHOOKURL = "your-external-url:" + PORT;
- public static final String INTERNALWEBHOOKURL = "your-internal-url:" + PORT;
- public static final String pathToCertificatePublicKey = "path/to/my/certkey.pem";
- public static final String certificatePublicKeyFileName = "certkey.pem";
+ public static final String EXTERNALWEBHOOKURL = "https://example.changeme.com:" + PORT; // https://(xyz.)externaldomain.tld
+ public static final String INTERNALWEBHOOKURL = "https://localhost.changeme.com:" + PORT; // https://(xyz.)localip/domain(.tld)
+ public static final String pathToCertificatePublicKey = "./YOURPEM.pem"; //only for self-signed webhooks
+ public static final String pathToCertificateStore = "./YOURSTORE.jks"; //self-signed and non-self-signed.
+ public static final String certificateStorePassword = "yourpass"; //password for your certificate-store
public static final String OPENWEATHERAPIKEY = "";
diff --git a/src/main/java/org/telegram/Main.java b/src/main/java/org/telegram/Main.java
index 474e4ff..0aef971 100644
--- a/src/main/java/org/telegram/Main.java
+++ b/src/main/java/org/telegram/Main.java
@@ -4,12 +4,7 @@ import org.telegram.telegrambots.TelegramApiException;
import org.telegram.telegrambots.TelegramBotsApi;
import org.telegram.telegrambots.logging.BotLogger;
import org.telegram.telegrambots.logging.BotsFileHandler;
-import org.telegram.updateshandlers.ChannelHandlers;
-import org.telegram.updateshandlers.DirectionsHandlers;
-import org.telegram.updateshandlers.FilesHandlers;
-import org.telegram.updateshandlers.RaeHandlers;
-import org.telegram.updateshandlers.TransifexHandlers;
-import org.telegram.updateshandlers.WeatherHandlers;
+import org.telegram.updateshandlers.*;
import java.io.IOException;
import java.util.logging.ConsoleHandler;
@@ -32,17 +27,44 @@ public class Main {
} catch (IOException e) {
BotLogger.severe("MAIN", e);
}
+ // default, start all sample bots in getUpdates mode
+ if (!BuildVars.useWebHook) {
+ TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
- TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
- try {
+ 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());
- } catch (TelegramApiException e) {
- BotLogger.error(LOGTAG, e);
+
+ } 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);
+ }
+
}
}
}
diff --git a/src/main/java/org/telegram/updateshandlers/webHookExampleHandlers.java b/src/main/java/org/telegram/updateshandlers/webHookExampleHandlers.java
new file mode 100644
index 0000000..d9c8a7a
--- /dev/null
+++ b/src/main/java/org/telegram/updateshandlers/webHookExampleHandlers.java
@@ -0,0 +1,47 @@
+package org.telegram.updateshandlers;
+
+import org.telegram.BotConfig;
+import org.telegram.BuildVars;
+import org.telegram.telegrambots.api.methods.BotApiMethod;
+import org.telegram.telegrambots.api.methods.send.SendMessage;
+import org.telegram.telegrambots.api.objects.Update;
+import org.telegram.telegrambots.bots.TelegramWebhookBot;
+import org.telegram.telegrambots.logging.BotLogger;
+
+/**
+ * Created by pithera on 5/31/16.
+ * Yes this is an ugly example, feel free to supply something nice.
+ */
+public class webHookExampleHandlers extends TelegramWebhookBot {
+ @Override
+ public BotApiMethod onWebhookUpdateReceived(Update update) {
+ BotLogger.severe("UPDATE", update.toString());
+ if (update.hasMessage() && update.getMessage().hasText()) {
+ SendMessage sendMessage = new SendMessage();
+ sendMessage.setChatId(update.getMessage().getChatId().toString());
+ sendMessage.setText("Your webhook works!, this is your callback:\n" + BuildVars.EXTERNALWEBHOOKURL + "/"
+ + "callback/" + getBotPath());
+ return sendMessage;
+ }
+ return null;
+ }
+
+
+ @Override
+ public String getBotUsername() {
+ return BotConfig.USERNAMEWEBHOOK;
+ }
+
+ @Override
+ public String getBotToken() {
+ return BotConfig.TOKENWEBHOOK;
+ }
+
+ @Override
+ public String getBotPath() {
+ return BotConfig.USERNAMEWEBHOOK;
+ } //arbitrary path to deliver updates on, username is an example.
+
+
+}
+