Giter Club home page Giter Club logo

Comments (3)

Fleker avatar Fleker commented on July 21, 2024 3

The Actions on Google library is focused on building and responding to Actions, and isn't intended to support responses to other platforms. Dialogflow does not appear to have a fulfillment library for Java. While you may be able to use the WebhookResponse object from this library, some additional work may need to be employed to get the response directly instead of using additional built-in methods.

from actions-on-google-java.

gad2103 avatar gad2103 commented on July 21, 2024 3

this is a problem for any case where there is the need to create or modify anything in the dialogflow payload. for example, if you want to modify a parameter in the query result and send the modified version back. The problem is in the following snippets:

// com/google/actions/api/impl/DialogflowResponse.kt

internal class DialogflowResponse internal constructor(
        responseBuilder: ResponseBuilder) : ActionResponse {
    override val webhookResponse: WebhookResponse
    override val appResponse: AppResponse? = null
    override val expectUserResponse: Boolean?
        get() = googlePayload?.expectUserResponse

    internal var conversationData: MutableMap<String, Any>? = null
    internal var googlePayload: AogResponse? = null
    internal var contexts: MutableList<ActionContext>? = ArrayList()
    internal var sessionEntityTypes: MutableList<SessionEntityType>? = ArrayList()
    internal var sessionId: String? = null

    init {
        conversationData = responseBuilder.conversationData
        sessionId = responseBuilder.sessionId
        if (responseBuilder.webhookResponse != null) {
            webhookResponse = responseBuilder.webhookResponse!!
        } else {
            webhookResponse = WebhookResponse()
        }
        if (webhookResponse.fulfillmentText == null) {
            webhookResponse.fulfillmentText = responseBuilder.fulfillmentText
        }
        googlePayload = responseBuilder.buildAogResponse()
    }

mainly the last line. googlePayload is always set here no matter what. which begs the question: why is it even a nullable type?

// com/google/actions/api/impl/io/ResponseSerializer.kt

    private fun serializeDialogflowResponseV2(
            dialogflowResponse: DialogflowResponse): String {
        val gson = GsonBuilder().create()
        val googlePayload = dialogflowResponse.googlePayload
        val webhookResponse = dialogflowResponse.webhookResponse
        val conversationData = dialogflowResponse.conversationData
        val contexts = dialogflowResponse.contexts
        val sessionEntityTypes = dialogflowResponse.sessionEntityTypes

        if (googlePayload != null) {
            val aogPayload = DialogflowGooglePayload(googlePayload)

            val map = HashMap<String, Any>()
            map["google"] = aogPayload
            webhookResponse.payload = map
        }

as you can see here the webhookResponse.payload just gets totally overwritten.

it seems like it should either:

  1. allow the googlePayload to be null for dialogflow response types
  2. and/or merge the maps rather than just overwrite.

if that is acceptable i'm happy to make a PR. This is causing us pain atm and i would love to fix. it also doesnt quite make sense why it is built this way from my perspective.

please consider re-opening and taking a PR!

from actions-on-google-java.

Fleker avatar Fleker commented on July 21, 2024

If you send a PR I'll take a look. As stated, this library is not meant for developing webhooks beyond AoG, but if the change is not too expansive and well tested I think it'll be fine to merge.

from actions-on-google-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.