call.receiveText() doesn't seem to cut it
# ktor
w
call.receiveText() doesn't seem to cut it
o
what’s not working?
w
I was expecting call.recieveText() to give the 'raw' json string
but it just gives an empty string
Copy code
val model : Model = call.receive<Model>()
this is giving the class initialized with JSON values correctly
o
I just added a test and it works as expected,
receiveText
returns an unprocessed string
Is it possible you are trying to receive a
Model
and a raw string? Input content can be consumed only once.
w
Copy code
post("/webhook", {
            val model : Model = call.receive<Model>()
            val goog = call.receiveText()
            println("hi " + goog)
            if (model.`object`=="page") {
                for (s in model.entry) {
                    println(s.messaging[0].message.text)
                }
                call.response.status(HttpStatusCode.fromValue(200))
                call.respondText("EVENT_RECEIVED")
            } else {
                call.respond(HttpStatusCode.NotFound)
            }
        })
        get("/webhook", {
            val VERIFY_TOKEN : String = "LazizaBaryani"
            val mode = call.parameters["hub.mode"]
            val token = call.parameters["hub.verify_token"]
            val challenge = call.parameters["hub.challenge"]
            if ((!mode.isNullOrEmpty()) && (!token.isNullOrEmpty())) {
                if (mode == "subscribe" && token == VERIFY_TOKEN) {
                    println("WEBHOOK_VERIFIED");
                    call.response.status(HttpStatusCode.fromValue(200))
                    call.respondText(challenge.toString())
                } else {
                    call.respond(HttpStatusCode.Forbidden)
                }
            }

        })
    })
o
Indeed, that’s what is happening.
w
ah how dumb of me 🙂
Thanks a lot doing it just once works
d
Going to add a note in the documentation about receiving just once
👍🏼 1
http://ktor.io/servers/requests.html#receiving-several-times Maybe they could actually throw an exception to help people with the diagnosis
w
Yes that would be helpful