0

TL;DR
How to configure Dialogflow intents to recognize if the user user input contains the phrase "Search product:" and:

  • If the input contains the phrase "Search product:" store everything after this phrase as "$session.parameter.prompt" and pass this parameter to PRODUCT_SEARCH webhook
  • If the input doesn't contain the phrase "Search product:" store the whole user input as "$session.parameter.prompt" and pass this parameter to GENERAL_SEARCH webhook

Example conversation 1
(user): Hi
(bot): Hi, how can I help?
(user): Search product: Great computer MMORPG games

bot executes PRODUCT_SEARCH webhook with input: "Great computer MMORPG games" because the input contained "Search product:" phrase

(bot):
$session.params.PRODUCT_SEARCH[0].title
$session.params.PRODUCT_SEARCH[0].description
$session.params.PRODUCT_SEARCH[1].title
$session.params.PRODUCT_SEARCH[1].description
$session.params.PRODUCT_SEARCH[2].title
$session.params.PRODUCT_SEARCH[2].description
(bot): Is there anything else I can help you with?
(user): No thanks
(bot): Ok, glad to have helped!
FLOW END

Example conversation 2
(user): Hi
(bot): Hi, how can I help?
(user): What is the difference between an MMORPG and an RPG computer game?

bot executes GENERAL_SEARCH webhook with input: "What is the difference between an MMORPG and an RPG computer game?" because the input DID NOT contain "Search product:" phrase

(bot): $session.params.GENERAL_SEARCH.output
(bot): Is there anything else I can help you with?
(user): What are some of the best RPG computer games?

bot executes GENERAL_SEARCH webhook with input: "What are some of the best RPG computer games?" because the input DID NOT contain "Search product:" phrase

(bot): $session.params.GENERAL_SEARCH.output (2nd webhook call output)
(bot): Is there anything else I can help you with?
(user): No
(bot): Ok, glad to have helped!
FLOW END

My take

My take is that this is an example of dealing with a user intent (do a general or product search) and a string parameter (long sentence to search) at the same time.

I was able to get the bot to work by taking a user_input parameter (@sys.any). Screenshots below:

enter image description here enter image description here

The problem is that this solution isn't very elegant and doesn't utilize Dialogflow intents which would help especially if the user writes another prompt for a webhook.

Question:
Is it possible to move this solution to Dialogflow intents? Ideally the intent would:

  1. recognize if there was the "Search product:" phrase (easy to do)
  2. store the rest of the intent input as a parameter to be passed to a webhook (don't know how to do).

This second part puzzles me. Is there some way to store everything what the user entered for an intent as a parameter? Note that the search phrases can be COMPLETELY different so creating an entity and training data for it doesn't seem like the most efficient option. The training data also seems like an overkill given the fact that it's a simple yes/no use case if there is a "Search product:" phrase.

da-veed
  • 11
  • 2
  • Do these [link1](https://cloud.google.com/dialogflow/cx/docs/quick/webhook) and [link2](https://github.com/hayo03/Dialogflow-CX-Start-Tutorial) help you? – kiran mathew May 28 '23 at 14:35
  • Nope. I'm already familiar with Dialogflow and its documentation. Also, I already created the necessary webhooks. What interests me is utilizing intents to pass user input to those webhooks. – da-veed May 30 '23 at 09:34
  • Hi @da-veed, I have posted a solution for your requirements based on your last comment . Do consider to upvoting and accepting if it helps, else let me know so that I can improve my answer. – – kiran mathew May 31 '23 at 13:26

1 Answers1

0

For your requirements, you can consider the below example:

In this example I am using productintent intent to find the product name from user input.

enter image description here

Whenever user input matches with intent training phrases,dialogflow cx fetch product name from that user input sentence.You can send product name to weebhook for further processes. In this example I am using gcp cloud function for the webhook service.

Cloud Function Code

from google.cloud import bigquery

client = bigquery.Client()
data=''

def handle_webhook(request):
  req = request.get_json()
  tag = req["fulfillmentInfo"]["tag"]
  if tag=="search":
      product=req["sessionInfo"]["parameters"]["any"]
      query = """ SELECT description FROM `my-project.database.table` where product=product  ; """
      results = client.query(query)
      for r in results:
          data=r[0]
      text=f"Title is :{product} \n  Description is : {data}"
      print(text)
  
  res = {"fulfillment_response": {"messages": [{"text": {"text": [text]}}]}}
  return res

In the above code I am using gcp bigquery as a database. By using a database you can store any amount of data. Here I am using the bigquery to store product description.

Simulator:

enter image description here

For more information you can refer to these link1 and link2.

kiran mathew
  • 1,882
  • 1
  • 3
  • 10
  • This does not answer the question. The `productintent` is supposed to take the ALL user input after "Search product:", not just specific words/entities. Please refer to the example conversations listed in the original question – da-veed Jun 05 '23 at 12:42
  • Hi @da-veed,In the Intent it seems like a feature request. If you want this feature to be implemented, you can open a new [feature request](https://cloud.google.com/support/docs/issue-trackers) on the issue tracker. As a workaround, you can take the full sentence as a parameter and then you can send it to webhook, on the webhook side you can process this sentence. But instead of sending all the sentences to the webhook, I recommend you to send the specific product name as I mentioned in my answer. You can send more than one parameter as a list at once. – kiran mathew Jun 09 '23 at 12:24