55import static com .github .stickerifier .stickerify .telegram .Answer .PRIVACY_POLICY ;
66import static java .util .Comparator .comparing ;
77
8+ import com .fasterxml .jackson .annotation .JsonProperty ;
89import com .github .stickerifier .stickerify .telegram .Answer ;
910import com .pengrad .telegrambot .model .Document ;
1011import com .pengrad .telegrambot .model .Message ;
2526 * @param message the message to wrap
2627 */
2728public record TelegramRequest (Message message ) {
28- public static final String NEW_USER = " (new user)" ;
29+
2930 private static final String START_COMMAND = "/start" ;
3031 private static final String HELP_COMMAND = "/help" ;
3132 private static final String PRIVACY_COMMAND = "/privacy" ;
@@ -77,24 +78,12 @@ public Integer getMessageId() {
7778 return message .messageId ();
7879 }
7980
80- /**
81- * Creates a String describing the current request,
82- * writing <b>only</b> the user identifier and if the sender is a new user.
83- *
84- * @return the description of the request
85- */
86- public String getDescription () {
87- var description = "request from user " + getUserId ();
88-
89- if (START_COMMAND .equals (message .text ())) {
90- description += NEW_USER ;
91- }
92-
93- return description ;
81+ private Long getUserId () {
82+ return message .from ().id ();
9483 }
9584
96- public Long getUserId () {
97- return message . from (). id ( );
85+ private boolean isNewUser () {
86+ return START_COMMAND . equals ( message . text () );
9887 }
9988
10089 public Answer getAnswerMessage () {
@@ -105,6 +94,10 @@ public Answer getAnswerMessage() {
10594 };
10695 }
10796
97+ public RequestDetails toRequestDetails () {
98+ return new RequestDetails (getUserId (), isNewUser ());
99+ }
100+
108101 @ Override
109102 public String toString () {
110103 var file = Optional .ofNullable (getFile ()).map (TelegramFile ::id ).orElse (null );
@@ -123,4 +116,6 @@ private static String writeIfNotEmpty(String field, @Nullable String value) {
123116 ? ", " + field + "=" + value
124117 : "" ;
125118 }
119+
120+ public record RequestDetails (@ JsonProperty ("user_id" ) Long userId , @ JsonProperty ("new_user" ) boolean isNewUser ) {}
126121}
0 commit comments