Bot Framework (.Net) - Send additional parameters with button using PromptDialog.Choice() - c#

I'm trying to learn Bot Framework using .Net and I have an application which displays buttons and based on the option selected, display more buttons or a list. What I want is, to send a hidden ID/parameter with the button so that when user clicks on the button, I can access the hidden parameter. I'm not using cards for this. I just want to display the buttons. Can anyone help me with this? I know this can be a very basic question but I couldn't find how to this without Cards.

First of all, PromptDialog.Choice behind the scenes creates a HeroCard with multiple buttons (which are basically the PromptOptions passed, see the code)
One way to pass a hidden parameter would be specifying the ActionType PostBack to your button and fill the Value property with the hidden parameter. PostBack is the way to go here since the message will be posted to the bot but client applications will not display this message (however, please note that not all the channels support the postBack action type). See this for more information
Now, since you are using PromptDialog.Choice you will have to override things in order to be able to specify the PostBack action type, since by default, the buttons created with the Choice are using ImBack (per this code)
You will have to put together a custom PromptStyler, override the Apply<T> method and add your logic to change the action type and set the buttons in the way you want based on the PromptStyle used and pass that custom styler to the PromptDialog.Choice.
By default the PromptDialog.Choice uses PromptStyle.Auto.

Related

Bot Framework Prompt Dialog with Image

I'm working with the Bot Framework and I want to display list of choices which have image attached by using method PromptDialog.Choice in order to take advantage of the ResumeAfterChoose method to control my business logic. However, I've only seen the Attachment Dialog which has written in EchoBot Sample and it only creates list of messages that make me difficult to handle my business logic after client choose one of the list. Please show me the way to implement that. Thanks
Out of the box, you can't do that. There are a few ways to achieve that though.
First of all, you are saying that using attachments won't work for you because you won't be able to handle your business logic. That's partially true; but not for the reason you are mentioning.
You could put together a list of HeroCards with buttons and use the carousel layout for the attachments (see the RichCards and the CarouselCards samples). Then, you can just perform a context.Wait to a different method (similar to the ResumeAfterChoose method in the PromptDialog) and handle the logic there. That method will get the value of the button clicked and then you can perform your business logic. Now... the caveat with that is that if the user writes anything not aligned to the options you still will hit this method.
Guess what? What I just described is extremely similar to what the PromptDialog.Choice does behind the scenes... with the only difference that it adds a Retry logic to handle the caveat I mentioned and that the layout used is a list one because it just render a single HeroCard with multiple buttons (the options)
The way I would go in this case, is trying to put together a custom PromptStyler, override the Apply<T> method and add your logic to render the Choice options in the way you want based on the PromptStyle used.
By default the PromptDialog.Choice uses PromptStyle.Auto, that at the end of the game (in the PromptStyler) converts the options into a HeroCard with multiple buttons. You could easily change that logic to create multiple cards and also uses images for them.

Modifying form fields with FieldEditingControls

I’m trying to add a honey pot field to our contact us form. When I add hidden field to the form via the Kentico GUI (with conditions making it invisible) it’s not available in the source so I don’t think it will actually work. However I also tried adding the form via the GUI and trying modify the style on prerender in my form control won’t work either (Code below). It is odd as it will actually let me change the value of the field in my form control but not the styling. Is this typical of Kentico and is there a solution to trying to implement a honeypot field? I had suggested we just add more validation methods to the form, but I was told that they want the same behavior as the existing forms.
Here is the method I’m using.
((CMS.FormControls.EditingFormControl)viewBiz.BasicForm.FieldEditingControls["Pooh"]).Style.Add("display", "none");
Thanks
Under the advanced properties of the field input, you should be able to apply styles to the input. You could set display:none; there to hide it from the user, but still have it available in the source.
I'm also going to create a form control for this so that it can easily be applied to another with some validation functionality (i.e. a redirect to captcha)

Orchard Custom Form DropDownLists

After a bit of playing around with Orchards' Custom Forms module, i decided i wanted to use a dropdownlist to select a particular person with their email as the value for that selected option. While i was creating the form i couldn't see anyway you could set values to your options.
See below image for example:
Don't suppose anybody has come across this before or has a suggestion?
In your case I wouldn't worry about having different text and values for the fields. It's also potentially dangerous to make the recipient email an input of the HTML form.
The Custom Form Rule Event provided with Orchard gives you no way to look at the values of the content type created by the form. So, you're probably going to have to write your own. You should be able to base this on Orchard.CustomForms.Rules.CustomFormEvents.
Armed with this you'd be able to create new rules for each possible dropdown value and set the email address in the action for each rule.

How do I know what is the type of control textbox/checkbox etc in controller?

I need to be dynamically build controls like textbox, checkbox, radiobutton etc by making a Ajax request and downloading the HTML. However once enough controls are on the screen and user submits the form, I need all the controls and it's posted values. Posted values are easy to get using Non sequential indices in Asp.Net MVC. But, how do I get which control's value it is? Put simply if the form has submitted the value "Hello World". I need to be able to know from where did the Hello World. Was the textbox that submitted this value or the textarea?
I don't need anything else like ID, name etc. Just need to know the type of control whether it was texbox, textarea, select or which one.
when you dynamically build these client elements, you give them a name so they will post to the server.
just follow a naming convention like:
textarea1,textarea2...
txt1,txt2,...
then at the server, to collect the values - take all the keys that start with textarea to collect the values of textAreas...
a nicer way will be to have a model with lists for each type, and when you generate the client elements, build their names so the values will be mapped to the correct list by the ModelBinder
the syntax for these names is a bit nasty so work with client templates
I used this post by haacked when i needed to build something like this
You need know more about http get or post.

how to check that any form field data is changed or not?

i am working on a asp.net web app in this application when customer logged in then his/her
personal details displayed in form fields (e.g. full name in name box ,age in age box etc) for getting data first i fetch the data from ms sql then assign them to ICustomer interface properties this interface is implemented by customer class.
And we also have a update button on customer information page so if without changing any information if a user click on update then unnecessary it will go to server and come back and the same data updated in database,so what i am trying to do is to just detect whether something changed in customer form then only update functionality should work.
i have two option
just use Java script and detected the text change then unable update button.
make a temporary reference of ICustomer and compare it to the older when then process by making something true or false.
so please suggest me the best approach for it or any other method.
if question is unclear then just comment on it i will explain more.
If you're using the formview or detailsview control in your asp.net webpage, then you can use the OldValues property of the forms's itemupdating event to compare the values before posting to your database. I believe the form's viewstate must be enabled for this to work.
protected void myFormView_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
// Access the old values
e.OldValues...
Here's a full example using the detailsview.
JavaScript may help you, but it's very unreliable. I say go with the second option. Store the ICustomer object in a Session variable and compare it with the new one.
If you're using TextBox controls, one option is to use the TextChanged event to detect changes.
You should go to 2nd option if the size of your object is not very large as you have to store the old object before comparing to the new object of Icustomer to detect any changes. Otherwise use javascript to detect the changes on the text fields. but as you know its not very much reliable.
the main problem with the Javascript option is that what if user changes value and again change to it's previous state in that case also it'll shows value changed.

Categories

Resources