Skip to content

Kotlin DSL for WhatsApp bot development

License

Notifications You must be signed in to change notification settings

blinkso/whatsappgraff

 
 

Repository files navigation

Telegraff

Settings

whatsapp.access-key=                  # api key
whatsapp.account-sid=                 # account sid
whatsapp.service-sid=                 # messaging service sid
whatsapp.mode=                        # polling (default), webhook
whatsapp.webhook-base-url=            # required for webhook mode
whatsapp.webhook-endpoint-url=        # optional

Usage

Add .kts in resource handlers folder: resources/handlers/ExampleHandler.kts.

enum class PaymentMethod {
    CARD, CASH
}

handler("/taxi") {
    step<String>("locationFrom") {
        question {
            MarkdownMessage("Start point:")
        }
    }

    step<String>("locationTo") {
        question {
            MarkdownMessage("Where to:")
        }
    }

    step<PaymentMethod>("paymentMethod") {
        question {
            MarkdownMessage("Card or cash?", "Card", "Cash")
        }

        validation {
            when (it.toLowerCase()) {
                "Card" -> PaymentMethod.CARD
                "Cash" -> PaymentMethod.CASH
                else -> throw ValidationException("You should choose one of the variants above")
            }
        }
    }

    process { state, answers ->
        val from = answers["locationFrom"] as String
        val to = answers["locationTo"] as String
        val paymentMethod = answers["paymentMethod"] as PaymentMethod

        // Business logic

        MarkdownMessage("Order confirmed. $from в $to. Payment $paymentMethod.")
    }
}

Error handling

Error handling

About

Kotlin DSL for WhatsApp bot development

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • Kotlin 100.0%