fixes in sample of business_connections bot

This commit is contained in:
InsanusMokrassar 2024-08-02 16:48:27 +06:00
parent f5a9efa3e7
commit f79e43364a

View File

@ -11,6 +11,7 @@ import dev.inmo.tgbotapi.extensions.api.send.send
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
import dev.inmo.tgbotapi.extensions.utils.accessibleMessageOrNull import dev.inmo.tgbotapi.extensions.utils.accessibleMessageOrNull
import dev.inmo.tgbotapi.extensions.utils.ifAccessibleMessage
import dev.inmo.tgbotapi.extensions.utils.ifBusinessContentMessage import dev.inmo.tgbotapi.extensions.utils.ifBusinessContentMessage
import dev.inmo.tgbotapi.extensions.utils.textContentOrNull import dev.inmo.tgbotapi.extensions.utils.textContentOrNull
import dev.inmo.tgbotapi.types.ChatId import dev.inmo.tgbotapi.types.ChatId
@ -55,13 +56,17 @@ suspend fun main(args: Array<String>) {
onContentMessage { onContentMessage {
it.ifBusinessContentMessage { businessContentMessage -> it.ifBusinessContentMessage { businessContentMessage ->
if (businessContentMessage.content.textContentOrNull() ?.text ?.startsWith("/pin") == true) { if (businessContentMessage.content.textContentOrNull() ?.text ?.startsWith("/pin") == true) {
pinChatMessage(businessContentMessage) businessContentMessage.replyTo ?.ifAccessibleMessage {
pinChatMessage(it)
return@ifBusinessContentMessage return@ifBusinessContentMessage
} }
}
if (businessContentMessage.content.textContentOrNull() ?.text ?.startsWith("/unpin") == true) { if (businessContentMessage.content.textContentOrNull() ?.text ?.startsWith("/unpin") == true) {
unpinChatMessage(businessContentMessage) businessContentMessage.replyTo ?.ifAccessibleMessage {
unpinChatMessage(it)
return@ifBusinessContentMessage return@ifBusinessContentMessage
} }
}
val sent = execute(it.content.createResend(businessContentMessage.from.id)) val sent = execute(it.content.createResend(businessContentMessage.from.id))
if (businessContentMessage.sentByBusinessConnectionOwner) { if (businessContentMessage.sentByBusinessConnectionOwner) {
reply(sent, "You have sent this message to the ${businessContentMessage.businessConnectionId.string} related chat") reply(sent, "You have sent this message to the ${businessContentMessage.businessConnectionId.string} related chat")