Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add custom payload for integrations #13

Closed
dmezei opened this issue Mar 1, 2019 · 3 comments
Closed

Cannot add custom payload for integrations #13

dmezei opened this issue Mar 1, 2019 · 3 comments

Comments

@dmezei
Copy link

dmezei commented Mar 1, 2019

Hi,
I tried to use this lib to handle fulfillment requests and respond with custom payload for my Dialogflow integrations. ex: Slack integration
I tried to use the WebhookResponse object and it's setPayload method to achieve this.
However when the ResponseBuilder.build method is called and the ActionResponse is converted into JSON the payload that I previously set is replaced with a google one. 'payload': {'google': { ... }}

Is there a way to construct responses for integrations with this lib?

I tried even the simplest use case when I add only a text with the ResponseBuilder but the message won't show up in Slack.

@Fleker
Copy link
Member

Fleker commented Mar 1, 2019

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.

@gad2103
Copy link

gad2103 commented Mar 2, 2021

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!

@Fleker
Copy link
Member

Fleker commented Mar 9, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants