Skip to content

Commit eb4bc80

Browse files
author
Andrey Sundukov
committed
asundukov path. add more handle types
1 parent c004046 commit eb4bc80

File tree

31 files changed

+391
-16
lines changed

31 files changed

+391
-16
lines changed

kotlin-telegram-framework/src/main/kotlin/io/cutebot/telegram/bot/StatefulBot.kt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package io.cutebot.telegram.bot
22

33
import io.cutebot.telegram.bot.block.BotBlock
4+
import io.cutebot.telegram.bot.model.Location
5+
import io.cutebot.telegram.bot.model.message.AudioMessage
6+
import io.cutebot.telegram.bot.model.message.ContactMessage
7+
import io.cutebot.telegram.bot.model.message.VoiceMessage
48
import io.cutebot.telegram.bot.model.message.DocumentMessage
9+
import io.cutebot.telegram.bot.model.message.LocationMessage
510
import io.cutebot.telegram.bot.model.message.PhotoMessage
611
import io.cutebot.telegram.bot.model.message.RawMessage
712
import io.cutebot.telegram.bot.model.message.TextMessage
813
import io.cutebot.telegram.bot.model.message.VideoMessage
14+
import io.cutebot.telegram.bot.model.message.VideoNoteMessage
915
import io.cutebot.telegram.bot.model.settings.ChatMessagesStrategy
16+
import io.cutebot.telegram.client.model.TgVenue
1017
import io.cutebot.telegram.interaction.model.ChatAnswer
1118

1219
abstract class StatefulBot(
@@ -44,6 +51,36 @@ abstract class StatefulBot(
4451
return currentBlock.getAnswer()
4552
}
4653

54+
if (message.videoNote != null) {
55+
currentBlock = currentBlock.handleVideoNote(VideoNoteMessage(message, message.videoNote))
56+
return currentBlock.getAnswer()
57+
}
58+
59+
if (message.voice != null) {
60+
currentBlock = currentBlock.handleVoice(VoiceMessage(message, message.voice))
61+
return currentBlock.getAnswer()
62+
}
63+
64+
if (message.audio != null) {
65+
currentBlock = currentBlock.handleAudio(AudioMessage(message, message.audio))
66+
return currentBlock.getAnswer()
67+
}
68+
69+
if (message.contact != null) {
70+
currentBlock = currentBlock.handleContact(ContactMessage(message, message.contact))
71+
return currentBlock.getAnswer()
72+
}
73+
74+
if (message.location != null) {
75+
val venue = TgVenue(
76+
location = message.location,
77+
title = "",
78+
address = ""
79+
)
80+
currentBlock = currentBlock.handleLocation(LocationMessage(message, venue))
81+
return currentBlock.getAnswer()
82+
}
83+
4784
return ChatAnswer.noAnswer()
4885
}
4986

kotlin-telegram-framework/src/main/kotlin/io/cutebot/telegram/bot/block/BotBlock.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package io.cutebot.telegram.bot.block
22

3+
import io.cutebot.telegram.bot.model.Location
4+
import io.cutebot.telegram.bot.model.message.AudioMessage
5+
import io.cutebot.telegram.bot.model.message.ContactMessage
36
import io.cutebot.telegram.bot.model.message.DocumentMessage
7+
import io.cutebot.telegram.bot.model.message.LocationMessage
48
import io.cutebot.telegram.bot.model.message.PhotoMessage
59
import io.cutebot.telegram.bot.model.message.TextMessage
610
import io.cutebot.telegram.bot.model.message.VideoMessage
11+
import io.cutebot.telegram.bot.model.message.VideoNoteMessage
12+
import io.cutebot.telegram.bot.model.message.VoiceMessage
713
import io.cutebot.telegram.interaction.model.ChatAnswer
814

915
interface BotBlock {
@@ -14,5 +20,9 @@ interface BotBlock {
1420
fun handlePhoto(message: PhotoMessage): BotBlock
1521
fun handleDocument(message: DocumentMessage): BotBlock
1622
fun handleVideo(message: VideoMessage): BotBlock
17-
23+
fun handleVideoNote(message: VideoNoteMessage): BotBlock
24+
fun handleVoice(message: VoiceMessage): BotBlock
25+
fun handleContact(message: ContactMessage): BotBlock
26+
fun handleLocation(message: LocationMessage): BotBlock
27+
fun handleAudio(message: AudioMessage): BotBlock
1828
}

kotlin-telegram-framework/src/main/kotlin/io/cutebot/telegram/bot/block/BotTextBlock.kt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package io.cutebot.telegram.bot.block
22

3+
import io.cutebot.telegram.bot.model.message.AudioMessage
4+
import io.cutebot.telegram.bot.model.message.ContactMessage
35
import io.cutebot.telegram.bot.model.message.DocumentMessage
6+
import io.cutebot.telegram.bot.model.message.LocationMessage
47
import io.cutebot.telegram.bot.model.message.PhotoMessage
58
import io.cutebot.telegram.bot.model.message.VideoMessage
9+
import io.cutebot.telegram.bot.model.message.VideoNoteMessage
10+
import io.cutebot.telegram.bot.model.message.VoiceMessage
611

712
interface BotTextBlock: BotBlock {
813
override fun handlePhoto(message: PhotoMessage): BotBlock {
@@ -16,4 +21,25 @@ interface BotTextBlock: BotBlock {
1621
override fun handleVideo(message: VideoMessage): BotBlock {
1722
return this
1823
}
19-
}
24+
25+
override fun handleVideoNote(message: VideoNoteMessage): BotBlock {
26+
return this
27+
}
28+
29+
override fun handleVoice(message: VoiceMessage): BotBlock {
30+
return this
31+
}
32+
33+
override fun handleAudio(message: AudioMessage): BotBlock {
34+
return this
35+
}
36+
37+
override fun handleContact(message: ContactMessage): BotBlock {
38+
return this
39+
}
40+
41+
override fun handleLocation(message: LocationMessage): BotBlock {
42+
return this
43+
}
44+
45+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.cutebot.telegram.bot.model
2+
3+
import io.cutebot.telegram.client.TelegramApi
4+
import io.cutebot.telegram.client.model.TgAudio
5+
6+
class Audio(
7+
audio: TgAudio,
8+
telegramApi: TelegramApi,
9+
botToken: String
10+
): Voice(audio, telegramApi, botToken) {
11+
val thumb = audio.thumb?.let { PhotoSize(audio.thumb, telegramApi, botToken) }
12+
val title = audio.title
13+
val performer = audio.performer
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.cutebot.telegram.bot.model
2+
3+
import io.cutebot.telegram.client.model.TgContact
4+
5+
class Contact internal constructor(
6+
tgContact: TgContact
7+
) {
8+
val phoneNumber = tgContact.phoneNumber
9+
10+
val firstName = tgContact.firstName
11+
12+
val lastName = tgContact.lastName ?: ""
13+
14+
val userId = tgContact.userId
15+
16+
val vcard = tgContact.vcard
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.cutebot.telegram.bot.model
2+
3+
import io.cutebot.telegram.client.model.TgVenue
4+
5+
class Location internal constructor(
6+
tgVenue: TgVenue
7+
) {
8+
val longitude = tgVenue.location.longitude
9+
10+
val latitude = tgVenue.location.latitude
11+
12+
val address = tgVenue.address
13+
14+
val title = tgVenue.title
15+
16+
val foursquareId = tgVenue.foursquareId
17+
18+
val foursquareType = tgVenue.foursquareType
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.cutebot.telegram.bot.model
2+
3+
import io.cutebot.telegram.client.TelegramApi
4+
import io.cutebot.telegram.client.model.TgVideoNote
5+
6+
class VideoNote internal constructor(
7+
tgVideoNote: TgVideoNote,
8+
api: TelegramApi,
9+
token: String
10+
): FileItem(api, token, tgVideoNote) {
11+
val fileSize: Int? = tgVideoNote.fileSize
12+
val length: Int = tgVideoNote.length
13+
val duration: Int = tgVideoNote.duration
14+
val thumb: PhotoSize? = tgVideoNote.thumb?.let { PhotoSize(it, api,token) }
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.cutebot.telegram.bot.model
2+
3+
import io.cutebot.telegram.client.TelegramApi
4+
import io.cutebot.telegram.client.model.TgVoice
5+
6+
open class Voice internal constructor(
7+
tgVoice: TgVoice,
8+
api: TelegramApi,
9+
token: String
10+
): FileItem(api, token, tgVoice) {
11+
val fileSize: Int? = tgVoice.fileSize
12+
val duration: Int = tgVoice.duration
13+
val mimeType: String? = tgVoice.mimeType
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.cutebot.telegram.bot.model.message
2+
3+
import io.cutebot.telegram.bot.model.Audio
4+
import io.cutebot.telegram.client.model.TgAudio
5+
6+
class AudioMessage(message: RawMessage, audio: TgAudio): Message(message) {
7+
val audio: Audio = Audio(audio, message.telegramApi, message.botToken)
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.cutebot.telegram.bot.model.message
2+
3+
import io.cutebot.telegram.bot.model.Contact
4+
import io.cutebot.telegram.client.model.TgContact
5+
6+
class ContactMessage(
7+
message: RawMessage,
8+
contact: TgContact
9+
): Message(message) {
10+
val contact: Contact = Contact(contact)
11+
}

0 commit comments

Comments
 (0)