Skip to content

Commit

Permalink
Up version of kotlin plugin. Created dsl methods for answer with noti…
Browse files Browse the repository at this point in the history
…fication and message in one time
  • Loading branch information
alexander.melnikov committed Apr 19, 2019
1 parent e4eeadc commit 7e8a0da
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle.kts
@@ -1,7 +1,7 @@
import java.net.URI

plugins {
kotlin("jvm") version "1.3.21"
kotlin("jvm") version "1.3.30"
}

project(":library") {
Expand Down
28 changes: 28 additions & 0 deletions library/src/main/kotlin/chat/tamtam/botsdk/scopes/Scope.kt
Expand Up @@ -343,6 +343,34 @@ interface Scope {
}
}

/**
* This method prepare notification
* This method use only like connector for [answerWith] methods, which contains parameter [RequestSendMessage]
*
* You need use it if you want answer on Callback with notification and message in one time
*
* @param answerParams - [AnswerParams] which contains [CallbackId] of [InlineKeyboard] and [UserId]
* @receiver - this is text for notification (Toast) for User
* @return - [PreparedAnswer] which contains [AnswerParams] and [AnswerCallback]
*/
suspend infix fun String.prepareNotification(answerParams: AnswerParams): PreparedAnswer {
val answerCallback = AnswerCallback(notification = this, userId = answerParams.userId.id)
return PreparedAnswer(answerCallback, answerParams)
}

/**
* This method answer on Callback by [CallbackId] with new message
* You can use it, if you want answer with notification and message in one time.
*
* @param sendMessage - message which you want send
* @receiver - this is [PreparedAnswer] which contains [AnswerParams] and [AnswerCallback]
*
* @return - look at [RequestsManager.answer]
*/
suspend infix fun PreparedAnswer.answerWith(sendMessage: RequestSendMessage): ResultRequest<Default> {
return requests.answer(answerParams.callbackId, AnswerCallback(sendMessage, answerCallback.userId, answerCallback.notification))
}

private suspend fun sendForUserOrChat(userId: UserId, chatId: ChatId, sendMessage: RequestSendMessage): ResultRequest<Message> {
check(chatId.id != -1L || userId.id != -1L) {
"ChatId or UserId must be correct, current both are -1L"
Expand Down

0 comments on commit 7e8a0da

Please sign in to comment.