Dialogflow CX: capture a parameter from an annoted training phrase - dialogflow-cx

I'm building a chatbot with the Dialogflow-CX V3 console. The bot allows users, among other things, to place an order for a new project. Each project must have a name, so I define a parameter called projectName that the user must provide. I have defined a custom entity type called projectNameText, a regex. I can capture projectName in a form using a typical Q-and-A format:
bot: What is the project name?
user: SalesPitch
But that is rather tedious. I want to allow more freeform user input and capture the projectName using an annotation on an intent training phrase.
bot: What would you like to do?
user: I'd like to make a new project called SalesPitch
When I define a training phrase for an intent like
I'd like to make a new project called Annabel
I can highlight Annabel in the console's intent editor and annotate that as an entity of type #projectNameText as described here. But that instantly creates a parameter with Parameter id projectNameText. And I cannot edit that Parameter id. I can't require that when Dialogflow matches that training phrase and extracts an entity of type projectNameText, it puts it into the parameter projectName. Dialogflow demands that it goes into a parameter called projectNameText. When I run the simulator and type input that matches that training phrase, Dialogflow does indeed correctly extract the entity, but will only create a parameter named projectNameText - I can see the name and value in the simulator.
This answer implies that I can send the matched entity into any parameter I want. That would be sensible. But how do I do it? I can't find any way to edit the parameter name in the Intent editor. All it gives me is this:
and I cannot change the Parameter Id.
I must be missing something really basic. Hints, please?

It is indeed not possible to edit the Parameter Id in the Intent Editor directly.
Instead, in the Intent Editor from the Build tab, accept the default Parameter Id, and Save the modified intent.
Then go to the tabs on the left of the Dialogflow CX console and choose the Manage tab. Choose Intents from the menu and find the intent you have just edited from the menu. Click the intent name to be given a different version of the Intent Editor. Same fields, same data, different functionality. In this different Intent Editor, click the Parameter Id you want to edit. It is now editable. Do not forget to hit Save after editing it.
From start to end, that took thirteen days to find. I posted here and received no answer. I finally subscribed to Google Cloud paid support and raised a support case and was given the answer in a video call with Google India. Perhaps it should be in the Google Documentation.

Related

Slack does not render properly a suer by userID through workflow

Save a userID in a google sheet doc.
Try to push a message in a chat with the userID (read from the doc) but instead of normal #AdamLol I see <#USERID123>.
Can I somehow see the real name?
Since at-handles can change, it's not recommended to rely on them. As such, you have three options in terms of output.
Name
Mention (user ID)
Email
You can pick between these options by choosing from the dropdown beside the variable

How do I initiate a dynamic user prompt depending on an API response in Bot Composer?

I have an API response in which a field gives me an array of objects. I want to prompt the user to select which one of these objects in the array they want to see the details of. For example, if the API response has a field like:
"field":[
{"number":"101","name":"abc","value":"final output 1"},
{"number":"102","name":"xyz","value":"final output 2"}
]
I want the prompt/card to ask which number and name the user wants to choose, accordingly I want to show the corresponding value to the user. The number of objects in the array can vary. I would prefer if this prompt is in the form of an adaptive card like the one in the attached image, but any solution would do using bot composer's capabilities.
One viable solution would be to build a card in code. You can parse the response from the API and use it to create a card which can then be sent by the bot. Since this is Composer, you can look into creating a custom action to hold this logic.
As the user AP01 has said, one good solution to this problem is to do it inside the code. You can create a custom component that will execute C#(or nodejs if you use that) code in which you can then easily deserialize/parse/process that json array and create a custom card that will then be display to the user. That is how I did it.

Saving user utterance in a parameter during no match intent on start page

I am trying to implement a search functionality using webhook. I want to save user utterance in a parameter in case user query does not match any intent on start page.
Is there any way to save user utterances in parameter so that it can be used by webhook . Currently no match intent is invoked correctly but utterance does not go to webhook.
You should be able to extract the original user query and pass it as a parameter to your CX agents using webhook.
To do so, you should enable the “Use Webhook” option on the specific route where you want the user query to be extracted. When that route is triggered, you should be able to extract the original user query in your Webhook Request’s query union field. Here are the four possible Webhook Request fields where you can extract the relevant data based on the input type that the user provided:
“text” field - if natural language text was provided as input.
“transcript” field - if natural language speech audio was provided as input.
“trigger_event” field - if an event was provided as input.
“trigger_intent” field - if an intent was provided as input.
The user query that you extracted can then be passed as a parameter to your CX agent by adding it to your WebhookResponse body inside either of the following field:
WebhookResponse.page_info.form_info.parameter_info[]
WebhookResponse.session_info.parameters
Here’s an example webhook response containing a session parameter:
jsonResponse = {
"session_info":
{
"parameters":
{
"parameter_name": "parameter value"
}
}
};
What you can do:
Create an intent (e.g. 'NoMatchUtterance')
Fully label any training frases (this could just be some random phrases) for this intent with the parameter-id no-match-utterance (or something else) of type #sys.any. This will make sure that any reply is caught.
Create a route with this intent, below routes that match any other, preset intents. In the fulfillment of this route, you can now use $session.params.no-match-utterance.
An example from my projects:

Attach meta data / custom data to slack messages sent through the API

I am developing a series of Slack apps for my workspace, and some of them are meant to interact with the content (messages) delivered by the other apps : extracting content IDs that may be referred to by other messages
A concrete example :
Suppose I have an app A "FindUser" that is capable of giving me the user profile when a slack user types find me#example.com, and it replies in the thread with a formatted view of the user profile
I am developing an app B "EditTags", which basically gives me a right click option with "edit tags" (see Slack's Interactive Components/Actions), the idea being that a user could first ask app A to find a user, and then right click on the reply from App A and click the "edit tags" action given by the other app. What this app B does it actually retrieve the tags for the user mentionned by the previous message from app A, and in another reply to the thread it gives some controls to either delete an existing tag OR it shows a select with autocomplete to add new tags.
The B app needs to retrieve the user ID that the A app mentionned previously. So I need some way to pass that data directly in the slack message. When looking at the examples, slack does not seem to provide a way to add arbitrary "metadata" to a message, am I wrong ? Do you have workaround for this ? I mean I could totally send the user ID say, in the footer, so I can just read the footer, but I was planning to use the footer for something else... Is there a way to pass metadata hrough properties that would be hidden to the end user ?
Although this does not feel relevant, I am building a slack nodeJS app using the node slack sdk (and especially the #slack/interactive-messages package)
For the most part the Slack API does not provide any official means to attach custom data / meta data to messages. But with some simple "hacks" it is still possible. Here is how:
Approach
The basic approach is to use an existing field of the message as container for your data. Obviously you want to pick a field that is not directly linked to Slack functionality.
Some field are not always needed, so you can just use that field as data container. Or if its needed, you can include the functional value of that field along with your custom data in the data container.
For example for message buttons you could use the value field of a button and structure your code in a way that you do not need it in its original function. Usually its sufficient to know which button the user client (via the name field), so the value field is free to be used for your custom data. Or you can include the functional value of your button along with the custom data in a data container (e.g. a JSON string) in that field.
Serialization
All messages are transported through HTTP and mostly encoded as UTF-8 in JSON. So you want to serialize / de-serialize your data accordingly, especially if its binary data. If possible I would recommend to use JSON.
Length
The maximum allowed length of most fields is documented in the official Slack API documentation. e.g. for the value field for message buttons can contain up to 2.000 characters. Keep in mind that you need to consider the length of your data after serialization. e.g. if you convert binary data into Base64 so it can be transported with HTTP you will end up with about 1.33 characters for every byte.
Contents
In general I would recommend to keep your data container as small as possible and not include the actual data, but only IDs. Here are two common approaches:
Include IDs of your data objects and load the actual objects
from a data store when the request is later processed.
Include the ID of server session and when processing the request you
can restore the corresponding server session which contains all data
objects.
In addition you might need to include functional values so that the functionality of the field you are using still works (e.g. value of a menu option, see below)
Implementation
Dialogs
Dialogs provide an official field for custom data called state. Up to 3.000 characters.
Message buttons
For Message buttons you can use the message action fields / value. Up to 2.000 characters. Its also possible to use the name field, but I would advise against it, because the maximum allowed length of that field is not documented.
Message menus
For Message menus you can use the value field of an option or the name field of the menu action.
Usually the value field is the better approach, since you have a documented max length of 2.000 and it gives you more flexibility. However, you will need to combine you custom data with the actual functional value for each option. Also, this will not work for dynamic select elements (like users), where you can not control the value field.
When using the name field note, keep in mind that the maximum allowed length of name is not documented, so you want to keep you data as short as possible. Also, if you want to use more than one menu per attachment you need to include the actual name of the menu into your data container.
Normal message attachments
Normal message attachments do not contain any suitable field to be used as container for custom data, since all fields are linked to Slack functionality.
Technically you could use the fallback field, but only if you are 100% sure that your app is never used on a client that can not display attachments. Otherwise your data will be displayed to the user.

How to know what InputParameters values are possible in Dynamics CRM Plugin context?

I'm trying to understand the plug-in sample from here.
There's this condition:
// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
Speaking generally, not just with regard to this sample, on what prior knowledge should I base my decision to access a specific property? How could I have known to test whether the InputParameters contains a "Target" key (I assume I'm not supposed to guess it)?
And on what basis could I have known to ask whether the "Target" mapped value is of Entity type, and not some other type?
I found this post from 2 years ago, and I've found this webpage, saying (emphasis is mine):
Within a plugin, the values in context.InputParameters and
context.OutputParameters depend on the message and the stage that you
register the plugin on. For example, "Target" is present in
InputParameters for the Create and Update messages, but not the
SetState message. Also, OutputParameters only exist in a Post stage,
and not in a Pre stage. There is no single source of documentation
that provides the complete set of InputParameters and OutputParameters
by message and stage.
From my searchings, a single source still doesn't exist, but maybe the possible values can be found using the Dynamics Online platform, somewhere deep down the Settings menu, maybe? Any source would be great.
I know this is an "old" question that already has been answered, but I think this can be helpful. I've built a small web page that contains all the messages with all the Input/Output parameters. You can access it from here:
The best practice for doing this is to use a strongly typed approach. If, for example, you want to know which propertes are available on a CreateRequest, you would do:
var createReq = new CreateRequest() { Parameters = context.InputParameters };
createReq.Target; // Has type Entity
Take a look at the full blog post explaining this approach: Tip: Proper handling of Plugin InputParameters
Original answer:
It depends on which request we are talking about. See Understand the data context passed to a plug-in on MSDN.
As an example, take a look at CreateRequest. One property of
CreateRequest is named Target, which is of type Entity. This is the
entity currently being operated upon by the platform. To access the
data of the entity you would use the name “Target” as the key in the
input parameter collection. You also need to cast the returned
instance.
Note that not all requests contain a Target property that is of type
Entity, so you have to look at each request or response. For example,
DeleteRequest has a Target property, but its type is EntityReference.
In summary: Look at the actual request, e.g the CreateRequest.
In 2011 someone actually generated typed properties based on the message type. Kind of neat: https://xrmpalmer.wordpress.com/2013/05/27/crm2011-plugin-inputparameter-and-outputparameter-helper/
It would show you want parameters are possible per message.

Resources