1
+ package com.pengrad.telegrambot.request
2
+
3
+ import com.pengrad.telegrambot.model.MessageEntity
4
+ import com.pengrad.telegrambot.model.request.ParseMode
5
+ import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter
6
+ import java.io.File
7
+
8
+ class SendPhoto private constructor(
9
+ chatId : Long? = null ,
10
+ channelUsername : String? = null ,
11
+
12
+ photoUrl : String? = null ,
13
+ photoFile : File ? = null ,
14
+ photoBytes : ByteArray? = null
15
+ ) : KAbstractMultipartRequest<SendPhoto>(
16
+ chatId = chatId,
17
+ channelUsername = channelUsername,
18
+
19
+ contentParameterName = " photo" ,
20
+ contentUrl = photoUrl,
21
+ contentFile = photoFile,
22
+ contentBytes = photoBytes,
23
+
24
+ defaultFileName = ContentTypes .PHOTO_FILE_NAME ,
25
+ defaultContentType = ContentTypes .PHOTO_MIME_TYPE
26
+ ) {
27
+
28
+ constructor (chatId: Long , photoUrl: String ) : this (
29
+ chatId = chatId,
30
+ channelUsername = null ,
31
+ photoUrl = photoUrl
32
+ )
33
+
34
+ constructor (channelUsername: String , photoUrl: String ) : this (
35
+ chatId = null ,
36
+ channelUsername = channelUsername,
37
+ photoUrl = photoUrl
38
+ )
39
+
40
+
41
+ constructor (chatId: Long , photoFile: File ) : this (
42
+ chatId = chatId,
43
+ channelUsername = null ,
44
+ photoFile = photoFile
45
+ )
46
+
47
+ constructor (channelUsername: String , photoFile: File ) : this (
48
+ chatId = null ,
49
+ channelUsername = channelUsername,
50
+ photoFile = photoFile
51
+ )
52
+
53
+
54
+ constructor (chatId: Long , photoBytes: ByteArray ) : this (
55
+ chatId = chatId,
56
+ channelUsername = null ,
57
+ photoBytes = photoBytes
58
+ )
59
+
60
+ constructor (channelUsername: String , photoBytes: ByteArray ) : this (
61
+ chatId = null ,
62
+ channelUsername = channelUsername,
63
+ photoBytes = photoBytes
64
+ )
65
+
66
+
67
+ @Deprecated(" Use constructor with chatId or channelUsername instead" , ReplaceWith (" SendPhoto(chatId, photo)" ))
68
+ constructor (chatId: Any , photo: String ) : this (
69
+ chatId = (chatId as ? Number )?.toLong(),
70
+ channelUsername = chatId as ? String ,
71
+ photoUrl = photo
72
+ ) {
73
+ checkDeprecatedConstructorParameters()
74
+ }
75
+
76
+ @Deprecated(" Use constructor with chatId or channelUsername instead" , ReplaceWith (" SendPhoto(chatId, photo)" ))
77
+ constructor (chatId: Any , photo: File ) : this (
78
+ chatId = (chatId as ? Number )?.toLong(),
79
+ channelUsername = chatId as ? String ,
80
+ photoFile = photo
81
+ ) {
82
+ checkDeprecatedConstructorParameters()
83
+ }
84
+
85
+ @Deprecated(" Use constructor with chatId or channelUsername instead" , ReplaceWith (" SendPhoto(chatId, photo)" ))
86
+ constructor (chatId: Any , photo: ByteArray ) : this (
87
+ chatId = (chatId as ? Number )?.toLong(),
88
+ channelUsername = chatId as ? String ,
89
+ photoBytes = photo
90
+ ) {
91
+ checkDeprecatedConstructorParameters()
92
+ }
93
+
94
+ @Suppress(" NOTHING_TO_INLINE" )
95
+ private inline fun checkDeprecatedConstructorParameters () {
96
+ if (this .chatId == null && this .channelUsername == null ) {
97
+ throw IllegalArgumentException (" chatId parameter must be either Long or String" )
98
+ }
99
+ }
100
+
101
+ var caption: String? by optionalRequestParameter()
102
+ var parseMode: ParseMode ? by optionalRequestParameter()
103
+ var captionEntities: List <MessageEntity >? by optionalRequestParameter()
104
+ var showCaptionAboveMedia: Boolean? by optionalRequestParameter()
105
+ var hasSpoiler: Boolean? by optionalRequestParameter()
106
+
107
+ fun caption (caption : String ) = applySelf { this .caption = caption }
108
+
109
+ fun parseMode (parseMode : ParseMode ) = applySelf { this .parseMode = parseMode }
110
+
111
+ fun captionEntities (captionEntities : List <MessageEntity >) = applySelf { this .captionEntities = captionEntities }
112
+
113
+ fun captionEntities (vararg captionEntities : MessageEntity ) = applySelf { this .captionEntities = captionEntities.toList() }
114
+
115
+ fun showCaptionAboveMedia (showCaptionAboveMedia : Boolean ) = applySelf { this .showCaptionAboveMedia = showCaptionAboveMedia }
116
+
117
+ fun hasSpoiler (hasSpoiler : Boolean ) = applySelf { this .hasSpoiler = hasSpoiler }
118
+
119
+ }
0 commit comments