Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

how to remove "Choose an item" text before suggestion #76

Closed
magnum opened this issue Jun 19, 2018 · 20 comments
Closed

how to remove "Choose an item" text before suggestion #76

magnum opened this issue Jun 19, 2018 · 20 comments

Comments

@magnum
Copy link

magnum commented Jun 19, 2018

Anytime I add Suggestion to agent, on facebook there's always a text added saying "Choose an item"
how can it be removed or translated?

@naranjja
Copy link

naranjja commented Jun 26, 2018

Same here, how do we change this? Thanks!

@naranjja
Copy link

naranjja commented Jun 26, 2018

So, what I did was go into /src/rich-responses/suggestions-response.js and modified the Suggestion constructor to include this.title besides this.replies:

constructor(suggestion) {
    super();
    this.platform = undefined;
    this.replies = []; 
    this.title = "Choose an item:"

Then, I set the value of this.title to the passed in value to the suggestion object:

} else if (typeof suggestion === 'object') {
    this.replies.push(suggestion.reply)
    this.title = suggestion.title

Lastly, I modified the getV2ResponseObject_() function so that it handles this.title for the Facebook response:

} else if (platform === PLATFORMS.FACEBOOK) {
    response = {
        quickReplies: {
            title: this.title,
            quickReplies: this.replies
        }
    }
}

Once that's done, you can make quick replies like this. First, make the first one with a title:

const quickReplies = new Suggestion({
    title: "My custom message",
    reply: "Option 1"
})

And then add the rest of the options like so:

quickReplies.addReply_("Option 2")
quickReplies.addReply_("Option 3")
quickReplies.addReply_("Option 4")

Lastly,

agent.add(quickReplies)

And it works!

@naranjja
Copy link

naranjja commented Jun 26, 2018

In case anyone's interested, here's my fork, the complete edited file, and the edits (Git diff).

@pranavgor
Copy link

hey @naranjja I made the changes in the respective folder (suggestions-response,js) but for some reasons those changes are not being reflected, is there anything more than just saving the file that I need to do ?

@pranavgor
Copy link

pranavgor commented Jul 5, 2018

I installed your github module itself, it works perfectly. Thanks @naranjja

@TexugoGaio
Copy link

TexugoGaio commented Jul 7, 2018

hey guys, I'm new to this platform, how do I use this @naranjja code in my project? How would they require them?
The suggestion call I'm doing so:
const { Suggestion} = require('dialogflow-fulfillment');

@naranjja
Copy link

naranjja commented Jul 7, 2018

@TexugoGaio In your project's package.json file, you would edit the version of "dialogflow-fulfillment" to the URL of my repo. Like this:

{
"dialogflow-fulfillment": "git+https://github.com/naranjja/dialogflow-fulfillment-nodejs.git"
}

@TexugoGaio
Copy link

thank you very much @naranjja, it worked perfectly!

@mattcarrollcode
Copy link
Contributor

Since this is a platform specific feature, it won't be supported in the library. If you'd like to use platform-specific responses, I'd recommend using the payload response type

@jdpt0
Copy link

jdpt0 commented Aug 15, 2018

@matthewayne Appreciate the great library, cheers for the great work. The issue with a quick reply payload is the limitation of not being able to send fulfillment messages along with a custom payload. The solution above supplied by @naranjja is a good work around until this functionality is added. There is a pull request pending that elevates this limitation. (#113) Any chance of getting this merged any time soon? Would be very useful for my current use case. Cheers.

@dadisigursveinn
Copy link

dadisigursveinn commented Nov 3, 2018

@matthewayne is there no way to change the

Choose an item

message on Facebook messenger without using Payload? Or to implement the feature without it needing to be platform specific.

@Vadorequest
Copy link

@matthewayne I understand what you're saying and the design choice. But the reality of this choice push developers to fork and use their own implementation of your library, which is really not a good thing.

Stepping back a bit, and after using this lib for 2 days, I can tell a proper abstraction of the specificities of each Platform is a must-have. For instance, in my case I need to deal with both Facebook and Web integrations, and I ended up writing wrappers around basic stuff like Text or Suggestion.

If you don't want to write custom integration code in this library, so be it. What do you think about writing a wrapper of your own library, or a bunch of helpers to deal with each platform specificities? It's something the community will need on the long-run.

Also, your link to payload response type is dead.

@magnum
Copy link
Author

magnum commented Dec 2, 2018

i solved using a custom payload as @matthewayne suggested: this way no fork is needed /cc @Vadorequest i'm using somthing like this

sendOptions(agent, options) {
    agent.add("please choose an item...")
    options.map(option => agent.add(new Suggestion(option)))
    let payload = new Payload(agent.FACEBOOK, {
      text: introText,
      quick_replies: options
        .slice(0, 5)
        .map(option => {
        return {
          content_type: "text",
          title: option,
          payload: option
        }
      })
    });
    agent.add(payload)
  }

@Vadorequest
Copy link

@magnum I don't understand why you send agent.add("please choose an item...") if you don't actually want it to be displayed. But I'm not so used to Dialogflow, getting started.

@magnum
Copy link
Author

magnum commented Dec 4, 2018

@magnum I don't understand why you send agent.add("please choose an item...") if you don't actually want it to be displayed. But I'm not so used to Dialogflow, getting started.

just saying this way you can customize it, for example translate it (that was my need) or for example not use it.

@jbonet
Copy link

jbonet commented Jan 29, 2019

How would this work for Telegram?

@Parau
Copy link

Parau commented Apr 4, 2019

i solved using a custom payload as @matthewayne suggested: this way no fork is needed /cc @Vadorequest i'm using somthing like this

sendOptions(agent, options) {
    agent.add("please choose an item...")
    options.map(option => agent.add(new Suggestion(option)))
    let payload = new Payload(agent.FACEBOOK, {
      text: introText,
      quick_replies: options
        .slice(0, 5)
        .map(option => {
        return {
          content_type: "text",
          title: option,
          payload: option
        }
      })
    });
    agent.add(payload)
  }

Tried this code but it worked only in the Dialogflow simulator not inside Facebook messenger...

@mv-aspect
Copy link

let payload = new Payload(agent.FACEBOOK, {
text: introText,
quick_replies: options
.slice(0, 5)
.map(option => {
return {
content_type: "text",
title: option,
payload: option
}
})
});
agent.add(payload)

That works for me in the FB messenger as well.

@rebuby9090
Copy link

@TexugoGaio In your project's package.json file, you would edit the version of "dialogflow-fulfillment" to the URL of my repo. Like this:

{
"dialogflow-fulfillment": "git+https://github.com/naranjja/dialogflow-fulfillment-nodejs.git"
}

what is dialogflow-fulfillment version which you editted?
It's 0.6.1 or lower?

@rebuby9090
Copy link

So, what I did was go into /src/rich-responses/suggestions-response.js and modified the Suggestion constructor to include this.title besides this.replies:

constructor(suggestion) {
    super();
    this.platform = undefined;
    this.replies = []; 
    this.title = "Choose an item:"

Then, I set the value of this.title to the passed in value to the suggestion object:

} else if (typeof suggestion === 'object') {
    this.replies.push(suggestion.reply)
    this.title = suggestion.title

Lastly, I modified the getV2ResponseObject_() function so that it handles this.title for the Facebook response:

} else if (platform === PLATFORMS.FACEBOOK) {
    response = {
        quickReplies: {
            title: this.title,
            quickReplies: this.replies
        }
    }
}

Once that's done, you can make quick replies like this. First, make the first one with a title:

const quickReplies = new Suggestion({
    title: "My custom message",
    reply: "Option 1"
})

And then add the rest of the options like so:

quickReplies.addReply_("Option 2")
quickReplies.addReply_("Option 3")
quickReplies.addReply_("Option 4")

Lastly,

agent.add(quickReplies)

And it works!

what is dialogflow-fulfillment version which you editted?
It's 0.6.1 or lower?

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

No branches or pull requests