forked from elbekD/kt-telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebhookExample.kt
46 lines (39 loc) · 1.39 KB
/
WebhookExample.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import com.elbekd.bot.Bot
import com.elbekd.bot.model.toChatId
import com.elbekd.bot.server
suspend fun main() {
val token = "<TOKEN>"
val username = "<BOT USERNAME>"
val bot = Bot.createWebhook(username, token) {
url = "<URL>"
// below is optional parameters
// certificate = Paths.get("<PATH TO CERTIFICATE>").toFile()
// maxConnections = 20
// allowedUpdates = listOf(AllowedUpdate.Message)
// setWebhookAutomatically = true
/*
Jetty server is used to listen to incoming request from Telegram servers.
Recommended way to use webhook is to set configured nginx as proxy server.
*/
server {
// run on localhost
host = "localhost"
// and listen to desired port
port = 5200
// configuring TLS layer if no nginx used
// tls {
// port = 443
// keyStorePath = "<PATH TO KEYSTORE>"
// keyStorePassword = "<KEYSTORE PASSWORD>"
// keyManagerPassword = "<KEY MANAGER PASSWORD>"
// }
}
}
bot.onCommand("/start") { (msg, _) ->
bot.sendMessage(msg.chat.id.toChatId(), "Hello World!")
}
bot.onCommand("/echo") { (msg, opts) ->
bot.sendMessage(msg.chat.id.toChatId(), "${msg.text} ${opts ?: ""}")
}
bot.start()
}