update
parent
8c813557fa
commit
e38ab9985a
@ -1,3 +1,7 @@
|
||||
### <a id="4.1.1"></a>4.1.1 ###
|
||||
1. Removed unsafe dependencies
|
||||
2. Fix bugs: #535, #524, #563, #562 and #557
|
||||
|
||||
### <a id="4.1"></a>4.1 ###
|
||||
1. Support for Api Version [4.1](https://core.telegram.org/bots/api-changelog#august-27-2018)
|
||||
2. Fix #507 and #512
|
||||
|
41
FAQ.md
41
FAQ.md
@ -1,4 +1,5 @@
|
||||
* [How to get picture?](#how_to_get_picture)
|
||||
* [How to get picture?](#how_to_get_picture)
|
||||
* [How to display ChatActions like "typing" or "recording a voice message"?](#how_to_sendchataction)
|
||||
* [How to send photos?](#how_to_send_photos)
|
||||
* [How do I send photos by file_id?](#how_to_send_photos_file_id)
|
||||
* [How to use custom keyboards?](#how_to_use_custom_keyboards)
|
||||
@ -74,6 +75,38 @@ public java.io.File downloadPhotoByFilePath(String filePath) {
|
||||
|
||||
The returned `java.io.File` object will be your photo
|
||||
|
||||
## <a id="how_to_sendchataction"></a>How to display ChatActions like "typing" or "recording a voice message"? ##
|
||||
Quick example here that is showing ChactActions for commands like "/type" or "/record_audio"
|
||||
|
||||
```java
|
||||
if (update.hasMessage() && update.getMessage().hasText()) {
|
||||
|
||||
String text = update.getMessage().getText();
|
||||
|
||||
SendChatAction sendChatAction = new SendChatAction();
|
||||
sendChatAction.setChatId(update.getMessage().getChatId());
|
||||
|
||||
if (text.equals("/type")) {
|
||||
// -> "typing"
|
||||
sendChatAction.setAction(ActionType.TYPING);
|
||||
// -> "recording a voice message"
|
||||
} else if (text.equals("/record_audio")) {
|
||||
sendChatAction.setAction(ActionType.RECORDAUDIO);
|
||||
} else {
|
||||
// -> more actions in the Enum ActionType
|
||||
// For information: https://core.telegram.org/bots/api#sendchataction
|
||||
sendChatAction.setAction(ActionType.UPLOADDOCUMENT);
|
||||
}
|
||||
|
||||
try {
|
||||
Boolean wasSuccessfull = execute(sendChatAction);
|
||||
} catch (TelegramApiException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## <a id="how_to_send_photos"></a>How to send photos? ##
|
||||
|
||||
There are several method to send a photo to an user using `sendPhoto` method: With a `file_id`, with an `url` or uploading the file. In this example, we assume that we already have the *chat_id* where we want to send the photo:
|
||||
@ -231,8 +264,6 @@ Your main spring boot class should look like this:
|
||||
|
||||
```java
|
||||
@SpringBootApplication
|
||||
//Add this annotation to enable automatic bots initializing
|
||||
@EnableTelegramBots
|
||||
public class YourApplicationMainClass {
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -246,10 +277,10 @@ public class YourApplicationMainClass {
|
||||
|
||||
After that your bot will look like:
|
||||
```java
|
||||
//Standart Spring component annotation
|
||||
//Standard Spring component annotation
|
||||
@Component
|
||||
public class YourBotClassName extends TelegramLongPollingBot {
|
||||
//Bot body.
|
||||
}
|
||||
```
|
||||
Also you could just implement LongPollingBot or WebHookBot interfaces. All this bots will be registered in context and connected to Telegram api.
|
||||
Also you could just implement LongPollingBot or WebHookBot interfaces. All this bots will be registered in context and connected to Telegram api.
|
||||
|
@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots</artifactId>
|
||||
<version>4.1</version>
|
||||
<version>4.1.1</version>
|
||||
</dependency>
|
||||
```
|
||||
* With **Gradle**:
|
||||
|
||||
```groovy
|
||||
compile group: 'org.telegram', name: 'telegrambots', version: '4.1'
|
||||
compile group: 'org.telegram', name: 'telegrambots', version: '4.1.1'
|
||||
```
|
||||
|
||||
2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).
|
||||
|
88
Handling-Bot-Tokens.md
Normal file
88
Handling-Bot-Tokens.md
Normal file
@ -0,0 +1,88 @@
|
||||
* [Bot Token Dont's](#bot-token-donts)
|
||||
* [Using Enviroment Variables](#using-environment-variables)
|
||||
* [Setting Enviroment Variables](#setting-environment-variables)
|
||||
* [Accessing Enviroment Variables](#accessing-enviroment-variables)
|
||||
* [Using Command Line Arguments](#using-command-line-arguments)
|
||||
|
||||
# <a id="bot-token-donts"></a> Bot Token Dont's ##
|
||||
* Tokens should not be hardcoded into the bot code
|
||||
* Tokens should never be published
|
||||
* Tokens should not be pushed into Repositorys
|
||||
|
||||
# <a id="using-environment-variables"></a> Using Environment Variables ###
|
||||
One convenient way to inject your bot token into the application is by using Environment Variables. Environment Variables are Values that are set in the Environment the Bot is running.
|
||||
|
||||
Those Values are not defined in the Application and therefore are not visible in the code.
|
||||
|
||||
## <a id="setting-environment-variables"></a> Setting Environment Variables ###
|
||||
|
||||
### Windows
|
||||
Enviroment Variables in Windows can be set using the Console (CMD) using
|
||||
```batchfile
|
||||
SETX [VARIABLE_NAME] [YOUR_BOT_TOKEN]
|
||||
```
|
||||
|
||||
It can also be set using the Windows GUI
|
||||
* From the desktop, right click the Computer icon.
|
||||
* Choose Properties from the context menu.
|
||||
* Click the Advanced system settings link.
|
||||
* Click Environment Variables...
|
||||
* In the 'User Variables for X' click New and enter a Name and your Token as the Value
|
||||
|
||||
### Linux & Mac
|
||||
* Open the '~/.bash_profile' File
|
||||
* Append the following to it:
|
||||
```bash
|
||||
export VARIABLE_NAME = {YOUR_BOT_TOKEN}
|
||||
```
|
||||
* Save the file
|
||||
* Either reboot your system or run the command above in your terminal
|
||||
|
||||
### IntelliJ
|
||||
* Go to Run->Edit Configuratuions...
|
||||
* Navigate to your Java Run Configuration
|
||||
* Under Enviroment->Enviroment Variables click the Folder Icon
|
||||
* Click the Plus Icon to add a new Variable
|
||||
* Enter a Name and your Token as the Value
|
||||
|
||||
###Heroku Cloud
|
||||
* Naviage to your App
|
||||
* In the Settings Tab under Config Vars, click "Reveal Config Vars"
|
||||
* Enter a Name and your Token as the Value
|
||||
* Click the "Add" button
|
||||
|
||||
## <a id="accessing-enviroment-variables"></a> Accessing Enviroment Variables ##
|
||||
|
||||
### Java
|
||||
You can access the Enviroment Variables by using System.getEnv()
|
||||
|
||||
```java
|
||||
String BOT_TOKEN = System.getenv("VARIABLE_NAME");
|
||||
```
|
||||
|
||||
### Spring
|
||||
|
||||
In Spring the @Value annotation allows you to inject the Value into your class
|
||||
```java
|
||||
public class Bot extends TelegramLongPollingBot {
|
||||
public Bot(@Value("${VARIABLE_NAME") String botToken) {
|
||||
this.botToken = botToken;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
# <a id="sing-command-line-arguments"></a> Using Command Line Arguments
|
||||
An easier but not Recommended way of injecting the Bottoken is by utilizing Command Line Arguments when starting the Application
|
||||
|
||||
In this case your main Method is responsible for taking in the Token
|
||||
|
||||
```java
|
||||
public static void main(String[] args) {
|
||||
String botToken = args[0];
|
||||
}
|
||||
```
|
||||
|
||||
You now have to call your jar by using
|
||||
```
|
||||
java -jar myBot.jar [BOT_TOKEN]
|
||||
```
|
2
Home.md
2
Home.md
@ -1,3 +1,3 @@
|
||||
Welcome to the TelegramBots wiki. Use the sidebar on the right. If you're not sure what to look at, why not take a look at the [[Getting Started|Getting-Started]] guide?
|
||||
|
||||
If you want more detailed explanations, you can also visit this [gitbook by MonsterDeveloper's](https://www.gitbook.com/book/monsterdeveloper/writing-telegram-bots-on-java/details)
|
||||
If you want more detailed explanations, you can also visit this [gitbook by MonsterDeveloper's](https://monsterdeveloper.gitbooks.io/writing-telegram-bots-on-java/content/)
|
||||
|
@ -3,6 +3,7 @@
|
||||
* [[Errors Handling]]
|
||||
* [[Using HTTP Proxy]]
|
||||
* [[FAQ]]
|
||||
* [[Handling Bot Tokens]]
|
||||
* AbilityBot
|
||||
* [[Simple Example]]
|
||||
* [[Hello Ability]]
|
||||
@ -11,5 +12,6 @@
|
||||
* [[Bot Testing]]
|
||||
* [[Bot Recovery]]
|
||||
* [[Advanced]]
|
||||
* [[Additional Examples]]
|
||||
* [[Changelog]]
|
||||
* [[How To Update]]
|
5
abilities/Additional-Examples.md
Normal file
5
abilities/Additional-Examples.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Additional Examples
|
||||
The following are nifty links to projects and examples that leverage the AbilityBot module. If you do have a project that you would like to share, please reach out!
|
||||
|
||||
[FitnessBot](https://craftcodecrew.com/getting-started-with-the-telegram-abilitybot/) -
|
||||
A fully fledged guide that walks you through building a fitness bot from A to Z
|
@ -9,12 +9,12 @@ As with any Java project, you will need to set your dependencies.
|
||||
<dependency>
|
||||
<groupId>org.telegram</groupId>
|
||||
<artifactId>telegrambots-abilities</artifactId>
|
||||
<version>4.1</version>
|
||||
<version>4.1.1</version>
|
||||
</dependency>
|
||||
```
|
||||
* **Gradle**
|
||||
```groovy
|
||||
compile group: 'org.telegram', name: 'telegrambots-abilties', version: '4.1'
|
||||
compile group: 'org.telegram', name: 'telegrambots-abilties', version: '4.1.1'
|
||||
```
|
||||
* [JitPack](https://jitpack.io/#rubenlagus/TelegramBots)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user