actions-on-google-kotlin icon indicating copy to clipboard operation
actions-on-google-kotlin copied to clipboard

Working on getting a simple v2 example going. Need some guidance

Open scottlahay opened this issue 6 years ago • 2 comments

I have been working on a google app engine project using the v2 branch. Looking for some guidence. I copied the DialogflowWebhook example and got a late init error that went away when I set Serializer.aogGson = Gson()

now I'm getting this exception

Uncaught exception from servlet java.lang.Error: No response has been set. Is this being used in an async call that was not returned as a promise to the intent handler? at actions.service.actionssdk.conversation.Conversation.response(Conversation.kt:391) at actions.service.dialogflow.DialogflowConversation.commonPayload(Conv.kt:321) at actions.service.dialogflow.DialogflowConversation.serialize(Conv.kt:366) at actions.service.dialogflow.DialogflowSdk$handler$1.handle(Dialogflow.kt:450) at actions.framework.StandardHandler$DefaultImpls.handle$default(Framework.kt:51) at actions.expected.ServletHandler.handle(BuiltinFrameworks.kt:36) at actions.service.dialogflow.DialogflowSdk$1.handle(Dialogflow.kt:463) at actions.ServiceBaseApp.invoke(Assistant.kt:21) at scott.servlets.FitnessAssistantServlet.simpleDialogFlowExample(FitnessAssistantServlet.kt:30) at scott.servlets.FitnessAssistantServlet.doPost(FitnessAssistantServlet.kt:21)

My code

data class MyConversation(val temp: String? = null)
data class MyArgument(val temp: String? = null, var resultType: String? = null, var userDescision: String? = null)

class FitnessAssistantServlet: HttpServlet() {
    val logger = Logger.getLogger("TestServlet")

    @Throws(ServletException::class, IOException::class)
    override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) {
        val dfApp = dialogflow<UserStorage<Any>, MyConversation, MyArgument>()
        dfApp.frameworks.add(ServletFramework())
        dfApp.intent("test") { conv -> conv.ask("Can you hear me?") }
        dfApp(req, res
    }
}

It feels like I'm missing some initialization logic somewhere, not sure where though. Thoughts?

scottlahay avatar Oct 16 '18 22:10 scottlahay

only thing that stands out right now is possibly adding multiple ServletFrameworks . Can you ensure that only one is added and test again?

patjackson52 avatar Nov 14 '18 18:11 patjackson52

As you asked I ensured the servlet framework is only getting initialized once. I did have to add org.slf4j:slf4j-jdk14:1.7.25 as a dependency. Different error!

My code

class MainServlet : HttpServlet() {

data class MyConversation(val temp: String? = null)
data class MyArgument(val temp: String? = null, var resultType: String? = null, var userDescision: String? = null)
var hasAddedFramework = false

@Throws(ServletException::class, IOException::class)
override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) {
    val dfApp = dialogflow<UserStorage<Any>, MyConversation, MyArgument>()
    if (!hasAddedFramework) {
        Serializer.aogGson = Gson()
        dfApp.frameworks.add(ServletFramework())
        hasAddedFramework = true
    }
    dfApp.intent("help") { conv -> conv.ask("Can you hear me?") }
    dfApp(req, resp)
}}

Log data

ava.lang.ClassCastException: org.eclipse.jetty.server.Request cannot be cast to actions.service.actionssdk.api.GoogleActionsV2AppRequest
at actions.service.dialogflow.DialogflowSdk$1.handle(Dialogflow.kt:466)
at actions.ServiceBaseApp.invoke(Assistant.kt:21)
at scott.servlets.MainServlet.actionsOnGoogleStuff(MainServlet.kt:38)
at scott.servlets.MainServlet.doPost(MainServlet.kt:26)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

I'm taking a look now, to see if I can figure out whats causing the class cast

scottlahay avatar Nov 14 '18 21:11 scottlahay