Covalent Telegram Bot. This time, java based

  • Name of the application
  • Java version being used
  • Spring boot we want to use
  • Different libraries to be added to the project
  • Spring-boot-starter-web
  • Spring-boot-devtools
  • Spring-boot-test
  • pom.xml defining the libraries that are going to be used in our project
  • CovalentRestController.java where we will be designing the logic of our application
  • ConnectionServiceImpl.java with the methods to execute HTTP requests
  • IConnectionService.java implementing the class ConnectionServiceImpl
  • SpringBootCovalentTelegramApplication.java being the entrance gate to our application, automatically generated and not needing any changes from our side
  • spring-boot-starter-web
  • spring-boot-devtools
  • spring-boot-test
  • okhttp3
  • okio
  • jcifs
  • It gets the requests coming from the Telegram API, with the payload of the request in JSON format, parsed as a map
  • It processes the text sent by the user, identifying the 3 parameters it needs according to the user’s input: “balance symbol address”
  • It executes the request to the service get token balances for address of Covalent’s API, using those 3 parameters we have just mentioned: symbol, address and chainId. It is highly recommended to check out the official Covalent documentation: https://www.covalenthq.com/docs/api/#get-/v1/{chain_id}/address/{address}/balances_v2/ As the documentation explains, we need a Covalent API key to use its services, adding it as a parameter in our requests.
  • It processes the response of Covalent API, extracting and calculating the needed information to generate the text message that will be bounced back to the user on Telegram.
  • Sends the response to the user in Telegram that requested it through the chat_id, generating it in the proper format. To know more about Telegram API the official docs are here: https://core.telegram.org/
  • As mentioned in those Telegram docs, to give the response back on a bot, we need the token associated to that bot, adding it to the request we are going to generate to reply to the users’ input:
  • We have to download and install Heroku Cli
  • We will open our command window and will log into our heroku account. For that we will execute heroku login
  • We will move in our system to the Spring Boot App folder.
  • Then we need to create a Git repository. If we don’t have GIT in our computer, we can download it here: https://git-scm.com/downloads
  • We execute git init
  • We execute then git add .
  • Finally we execute git commit –m “first commit”
  • For the first deployment we need to execute heroku create
  • From now on, for each “push” we do, it will mean that the service gets deployed on Heroku. For that we will execute git push heroku master
  • We can execute many deployments, doing new “commits” with our project, and after that, the corresponding “push”

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store