- Create feature instance in implementation of BaseLocationConfig
val adminsFeature by lazy {
AdminsFeature(
tgUser = tgUser,
userSelector = { userId: Long -> transaction { ComplaintsTgUser.findById(userId) } },
usersSelector = { transaction { ComplaintsTgUser.all() } }
)
}
- Use feature in global CallbackQueryHandler and CommandHandler
global {
handleCallbackQuery(handlerId = "global") {
if (tgUser.isAdmin) {
setupFeatures(adminsFeature)
}
}
handleCommand(handlerId = "global") {
if (tgUser.isAdmin) {
setupFeatures(adminsFeature)
}
}
}
- Create private static base instance in companion object of BaseLocationConfig
companion object {
private val baseAuthGoogleSheetsFeature = AuthGoogleSheetsFeature(
tgUser = TgUser(EntityID(0, TgUsers)),
sheetService = SheetService,
phonesSpreadsheetId = phonesSpreadsheetId,
getPhone = { message.contact?.phoneNumber?.phoneFormatted() },
onFail = { send("Вашего телефона нет среди разрешенных. ${contactEmail?.let { "Обратитесь на почту $it, чтобы вас добавили в систему." }}") },
onSuccess = { phone, _ ->
suspendTransaction {
tgUser.phone = phone
tgUser.isRegistered = true
tgUser.location = Location.MENU
tgUser.provideCommands()
sendWelcomeMessage()
}
}
)
}
- Create feature instance in implementation of BaseLocationConfig
val authGoogleSheetsFeature by lazy {
baseAuthGoogleSheetsFeature.copy(tgUser = tgUser)
}
- Use feature in global MessageHandler
global {
handleMessage(handlerId = "global") {
if (!tgUser.isRegistered) {
setupFeatures(authGoogleSheetsFeature)
}
}
}