Skip to content

Instantly share code, notes, and snippets.

@jagedn
Last active December 12, 2019 15:59
Show Gist options
  • Save jagedn/38a5d4ff65197d8b0ac6897ae9f102d9 to your computer and use it in GitHub Desktop.
Save jagedn/38a5d4ff65197d8b0ac6897ae9f102d9 to your computer and use it in GitHub Desktop.
package mn.telegram
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.Produces;
import javax.inject.Inject
import com.puravida.mn.telegram.*
@Controller("/hello")
public class HelloController {
@Inject
TelegramBot telegramBot
@Get("/")
@Produces(MediaType.TEXT_PLAIN)
public String index() {
Message message = new Message(chat_id:"-1001382561920",text:"hola from telegram api")
telegramBot.sendMessage(message).subscribe({ ok->
byte[] image = "http://mars.jpl.nasa.gov/msl-raw-images/proj/msl/redops/ods/surface/sol/01000/opgs/edr/fcam/FLB_486265257EDR_F0481570FHAZ00323M_.JPG".toURL().bytes
SendPhoto photo = new SendPhoto(chat_id:"-1001382561920",bytes:image)
telegramBot.sendPhoto(photo.multipartBody()).subscribe()
},{ error->
println error
})
return "Hello World";
}
}

Workshop: Build a Telegram Bot with Micronaut

Requirements

  • Docker

  • Java/Groovy

  • Telegram in your mobile phone

  • Heroku account and Heroku cli installed

Theory

  • Architecture

  • Channel

  • Chat

  • Others (not covered in this workshop): games, money

  • Bot

    • push

    • pull

BotFather

  • create bot

  • config bot

  • keep your Token secret

Channel

  • Public vs Private

  • Sending messages to a channel

  • Sending multimedia to a channel

Chat

  • Dockerize and publish to Heroku

  • Starting a chat

  • Answering to the user

  • Sending multimedia to the user

  • Commands and Keyboards

  • InlineKeyboards and Callbacks

  • Dialog

Heroku Alternatives

  • Google AppEngine (Grails)

  • Google Run

  • Digital Ocean

  • Okteto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment