Closed saiid2020 closed 5 years ago
I use gradle and so far I have not used maven. How to use this api in Android programming
Gradle is similar, cause the library is not on Maven Center or JCenter yet, so you need to build the jar library by using ./mvnw clean install
, then you will find the jar file under target folder.
Then you can add the jar file inside your Android project, then start using it. I can coach you about how to do Android programming, but the example code about how to call bot API is in README.md, you need to find a suitable place to put them in your Android project, for example a daemon / background service / thread.
io.sgr.telegram.bot.engine.BotEngine This library does not exist in Jar. Can not use BotEngein .
That because you might missed the jar file.
This project contains two major Maven modules. One is the bot client api, which contains implementations of most Telegram Bot API, there are a few haven't been implemented. The other is bot engine, which you can use to create a standalone application which act as the backend of your bot. Obviously in order to interact with Telegram server, bot engine needs to use the bot client api library to send REST request to the server.
So, in order to use io.sgr.telegram.bot.engine.BotEngine you need bot engine library and also client api library. You should find at least following jar files after a successful build:
api/target/telegram-bot.api-1.0.0-SNAPSHOT.jar
engine/target/telegram-bot.engine-1.0.0-SNAPSHOT.jar
examples/**/target/*.jar
extentions/**/target/*.jar
You can't use BotEngine if you don't put telegram-bot.engine-1.0.0-SNAPSHOT.jar in your lib folder along with telegram-bot.api-1.0.0-SNAPSHOT.jar
I encountered this error after adding the library to rebuild it: Invoke-custom are only supported with Android O (--min-api 26). my project minimum api :16
I assume you compile my library using Java 8.
You need to understand one thing before you start building Android apps, in order to use Java 8 or higher on Android devices, you need to set minSdkVersion as suggested. You can find more details about it here: https://developer.android.com/studio/write/java8-support
According to the error message, you need to set it to at least 26.
One more advice, Android is really not a good place to run the backend of a Telegram bot, the users of your bot won't be able to receive response from your bot unless you opened the app. Also you don't want every user of your app can receive messages from your bot, that will definitely cause some chaos.
Well, the question is a little bit too general. I assume you're a Java developer and have basic knowledge about Telegram bot API. You can start with clone this repo to your local, run
mvn clean install
, then create another Maven project to host your own bot, and add this library to the dependencies. You can use the sample code in README.md, all you have to do is deal the updates received which represent the messages other people sent to your bot.