1
+ package com.pengrad.telegrambot.request
2
+
3
+ import com.pengrad.telegrambot.model.LinkPreviewOptions
4
+ import com.pengrad.telegrambot.model.MessageEntity
5
+ import com.pengrad.telegrambot.model.request.ParseMode
6
+ import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter
7
+ import com.pengrad.telegrambot.utility.kotlin.requestParameter
8
+
9
+ class SendMessage private constructor(
10
+ chatId : Long? = null ,
11
+ channelUsername : String? = null ,
12
+
13
+ text : String
14
+ ) : KAbstractSendRequest<SendMessage>(
15
+ chatId = chatId,
16
+ channelUsername = channelUsername,
17
+ ) {
18
+
19
+ constructor (chatId: Long , text: String ) : this (
20
+ chatId = chatId,
21
+ channelUsername = null ,
22
+ text = text
23
+ )
24
+
25
+ constructor (channelUsername: String , text: String ) : this (
26
+ chatId = null ,
27
+ channelUsername = channelUsername,
28
+ text = text
29
+ )
30
+
31
+ @Deprecated(" Use constructor with chatId or channelUsername instead" , ReplaceWith (" SendMessage(chatId, text)" ))
32
+ constructor (chatId: Any , text: String ) : this (
33
+ chatId = (chatId as ? Number )?.toLong(),
34
+ channelUsername = chatId as ? String ,
35
+ text = text
36
+ ) {
37
+ checkDeprecatedConstructorParameters()
38
+ }
39
+
40
+ @Suppress(" NOTHING_TO_INLINE" )
41
+ private inline fun checkDeprecatedConstructorParameters () {
42
+ if (this .chatId == null && this .channelUsername == null ) {
43
+ throw IllegalArgumentException (" chatId parameter must be either Long or String" )
44
+ }
45
+ }
46
+
47
+ val text: String by requestParameter(text)
48
+
49
+ var parseMode: ParseMode ? by optionalRequestParameter()
50
+ var entities: List <MessageEntity >? by optionalRequestParameter()
51
+ var linkPreviewOptions: LinkPreviewOptions ? by optionalRequestParameter()
52
+
53
+ fun parseMode (parseMode : ParseMode ) = applySelf { this .parseMode = parseMode }
54
+
55
+ fun entities (entities : List <MessageEntity >) = applySelf { this .entities = entities }
56
+
57
+ fun entities (vararg entities : MessageEntity ) = entities(entities.toList())
58
+
59
+ fun linkPreviewOptions (linkPreviewOptions : LinkPreviewOptions ) = applySelf { this .linkPreviewOptions = linkPreviewOptions}
60
+
61
+ }
0 commit comments