Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

73 changes: 12 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,22 @@
<div align="center">
<img src="https://github.com/addo37/AbilityBots/blob/gh-pages/images/API%20BOT-03.png?raw=true" alt="abilitybots" width="200" height="200"/>

[![Build Status](https://travis-ci.org/addo37/ExampleBots.svg?branch=master)](https://travis-ci.org/addo37/ExampleBots)
[![Jitpack](https://jitpack.io/v/addo37/ExampleBots.svg)](https://jitpack.io/#addo37/ExampleBots)
[![Telegram](http://trellobot.doomdns.org/telegrambadge.svg)](https://telegram.me/AbilityBots)
[![Jitpack](https://jitpack.io/v/addo37/ExampleBots.svg)](https://jitpack.io/#addo37/ExampleBots)
[![Telegram](https://telegram-badge.vercel.app/api/telegram-badge?channelId=@AbilityBots)](https://telegram.me/AbilityBots)
</div>

Example Bots
------------
# Example Bots

Your entry point should be the **[ExampleBot](./src/main/java/org/telegram/examplebots/ExampleBot.java)**, it showcases most of the features of the AbilityBot.
Small, up-to-date samples of [telegrambots](https://github.com/rubenlagus/TelegramBots) 9.2 ability bots built with Java 25.

Don't forget that you can do the following with ANY AbilityBot!
## Quick start

* /claim - Claims this bot
* /commands - Reports all user-defined commands (abilities)
* /backup - Returns a backup of the bot database
* /recover - Recovers the database
* /promote @username- Promotes user to bot admin
* /demote @username - Demotes bot admin to user
* /ban @username - Bans the user from accessing your bot commands and features
* /unban @username - Lifts the ban from the user
- Set `BOT_TOKEN` and `BOT_USERNAME` in `src/main/java/org/telegram/examplebots/Application.java`, then choose whether to register `ExampleBot` or the minimal `HelloBot`.
- Run `./gradlew test` to ensure the project compiles and the mocked sender test still passes.
- Launch `Application.main()` from your IDE (or wire the class into your own host) to start long polling your bot.

Sample:
## What's inside

```java
public Ability saysHelloWorld() {
return Ability.builder()
.name("hello") // Name and command (/hello)
.info("Says hello world!") // Necessary if you want it to be reported via /commands
.privacy(PUBLIC) // Choose from Privacy Class (Public, Admin, Creator)
.locality(ALL) // Choose from Locality enum Class (User, Group, PUBLIC)
.input(0) // Arguments required for command (0 for ignore)
.action(ctx -> {
/*
ctx has the following main fields that you can utilize:
- ctx.update() -> the actual Telegram update from the basic API
- ctx.user() -> the user behind the update
- ctx.firstArg()/secondArg()/thirdArg() -> quick accessors for message arguments (if any)
- ctx.arguments() -> all arguments
- ctx.chatId() -> the chat where the update has emerged

NOTE that chat ID and user are fetched no matter what the update carries.
If the update does not have a message, but it has a callback query, the chatId and user will be fetched from that query.
*/
// Custom sender implementation
sender.send("Hello World!", ctx.chatId());
})
.build();
}
```

Testing
-------
Check out the **[ExampleBotTest](./src/test/java/org/telegram/examplebots/ExampleBotTest.java)** on how you can harness the power of mocked senders!

Sample
```java
@Test
public void canSayHelloWorld() {
Update mockedUpdate = mock(Update.class);
EndUser endUser = EndUser.endUser(USER_ID, "Abbas", "Abou Daya", "addo37");
MessageContext context = new MessageContext(mockedUpdate, endUser, CHAT_ID);

bot.saysHelloWorld().consumer().accept(context);

// We verify that the sender was called only ONCE and sent Hello World to CHAT_ID
Mockito.verify(sender, times(1)).send("Hello World!", CHAT_ID);
}
```
- `ExampleBot` shows admin/public abilities, forced replies, photo-only handlers, and `/count` storage using the AbilityBot database. Built-in AbilityBot commands such as `/claim`, `/commands`, `/backup`, etc. remain available out of the box.
- `HelloBot` is a bare-bones hello-world ability for stripping the setup down to the essentials.
- `ExampleBotTest` demonstrates how to plug in Mockito and the `SilentSender` to unit test your abilities without calling Telegram.
22 changes: 13 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
group 'org.telegram'
version '1.0'

apply plugin: 'java'
plugins {
id 'java'
}

sourceCompatibility = 1.8
java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
}

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}

dependencies {
compile 'org.telegram:telegrambots-abilities:3.4'
compile 'org.telegram:telegrambots:2.4.4.5'
implementation 'org.telegram:telegrambots-abilities:9.2.0'
implementation 'org.telegram:telegrambots-longpolling:9.2.0'
implementation 'org.telegram:telegrambots-client:9.2.0'

testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile 'org.mockito:mockito-all:2.0.2-beta'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:5.21.0'
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Sun Feb 19 22:11:08 EET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip
Loading