I'm trying to use adaptive cards by adding it on my luis response, and was following a guide: https://learn.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-add-rich-card-attachments.
How come my buttons is not showing up on my bot emulator? did i miss anything? see picture:
my code:
[LuisIntent("Test")]
public async Task Test(IDialogContext context, LuisResult result)
{
Activity replyToConversation = (Activity)context.MakeMessage();
//Activity replyToConversation = message.CreateReply("Should go to conversation");
replyToConversation.Attachments = new List<Attachment>();
AdaptiveCard card = new AdaptiveCard();
// Add text to the card.
card.Body.Add(new TextBlock()
{
Text = "Adaptive Card design session",
Size = TextSize.Large,
Weight = TextWeight.Bolder
});
// Add text to the card.
card.Body.Add(new TextBlock()
{
Text = "Conf Room 112/3377 (10)"
});
// Add text to the card.
card.Body.Add(new TextBlock()
{
Text = "12:30 PM - 1:30 PM"
});
// Add list of choices to the card.
card.Body.Add(new ChoiceSet()
{
Id = "snooze",
Style = ChoiceInputStyle.Compact,
Choices = new List<Choice>()
{
new Choice() { Title = "5 minutes", Value = "5", IsSelected = true },
new Choice() { Title = "15 minutes", Value = "15" },
new Choice() { Title = "30 minutes", Value = "30" }
}
});
// Add buttons to the card.
card.Actions.Add(new HttpAction()
{
Url = "http://foo.com",
Title = "Snooze"
});
card.Actions.Add(new HttpAction()
{
Url = "http://foo.com",
Title = "I'll be late"
});
card.Actions.Add(new HttpAction()
{
Url = "http://foo.com",
Title = "Dismiss"
});
// Create the attachment.
Attachment attachment = new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = card
};
replyToConversation.Attachments.Add(attachment);
// var reply = await connector.Conversations.SendToConversationAsync(replyToConversation);
await context.PostAsync(replyToConversation);
context.Done(true);
}
Change your HttpAction to OpenUrlAction (or SubmitAction, depending on your needs) and you will get your buttons:
When you look at the documentation, Actions possibilities are:
Action.OpenUrl
Action.Submit
Action.ShowCard
Their equivalent in C# objects are OpenUrlAction, SubmitAction and ShowCardAction
Related
Hi I am developing a chatbot on amazon lex and I want to send a response card using the lambda function but on using response card function inside the close response format it gives the error of null exception. Can anyone tell the solution to it?
PS I am using FlowerOrder blueprint created by Nikki.
if (slots[greet] != null)
{
var validateGreet = ValidateUserGreeting(slots[greet]);
if (validateGreet.IsValid)
{
return Close(sessionAttributes,
"Fulfilled",
new LexResponse.LexMessage
{
ContentType = "PlainText",
Content = String.Format("Hello Kindly choose one option")
},
new LexResponse.LexResponseCard
{
Version = 1,
ContentType = "application/vnd.amazonaws.card.generic",
GenericAttachments =
{
new LexResponse.LexGenericAttachments
{
Buttons =
{
new LexResponse.LexButton
{
Text = "Shop Now",
Value = "Shop Now"
}
},
AttachmentLinkUrl = null,
Title = "Shopping",
SubTitle = "Sub Shopping",
ImageUrl = null
}
}
}
);
}
Exception:-
2020-06-09 17:31:20: Object reference not set to an instance of an object.: NullReferenceException at EVS_Test_Abbar_Lambda_Function.OrderWatchIntentProcessorTest.Process(LexEvent lexEvent, ILambdaContext context) in D:\AWS Project\Abbrar Projects\EVS_Test_Abbar_Lambda_Function\EVS_Test_Abbar_Lambda_Function\OrderWatchIntentProcessorTest.cs:line 52 at EVS_Test_Abbar_Lambda_Function.Function.FunctionHandler(LexEvent lexEvent, ILambdaContext context) in D:\AWS Project\Abbrar Projects\EVS_Test_Abbar_Lambda_Function\EVS_Test_Abbar_Lambda_Function\Function.cs:line 43
at lambda_method(Closure , Stream , Stream , LambdaContextInternal )
Here is the solution to it since if you look at the structure of JSON it contains many models and lists and each has to be handled separately.
LexResponse.LexResponseCard lexResponseCard = new LexResponse.LexResponseCard();
List<LexResponse.LexGenericAttachments> ListlexGenericAttachments = new List<LexResponse.LexGenericAttachments>();
LexResponse.LexGenericAttachments lexGenericAttachments = new LexResponse.LexGenericAttachments();
List<LexResponse.LexButton> ListlexButton = new List<LexResponse.LexButton>();
LexResponse.LexButton lexButton = new LexResponse.LexButton();
lexButton.Text = "Yes Now";
lexButton.Value = "Yes";
ListlexButton.Add(lexButton);
lexGenericAttachments.AttachmentLinkUrl = "Link";
//lexGenericAttachments.AttachmentLinkUrl = null;
lexGenericAttachments.Title = "Shopping";
lexGenericAttachments.SubTitle = "Sub Shopping";
lexGenericAttachments.ImageUrl = "Link";
//lexGenericAttachments.ImageUrl = null;
lexGenericAttachments.Buttons = ListlexButton;
ListlexGenericAttachments.Add(lexGenericAttachments);
lexResponseCard.Version = 0;
lexResponseCard.ContentType = "application/vnd.amazonaws.card.generic";
lexResponseCard.GenericAttachments = ListlexGenericAttachments;
return Close(sessionAttributes,
"Fulfilled",
new LexResponse.LexMessage
{
ContentType = "PlainText",
Content = String.Format("Hello Kindly choose one option")
},
lexResponseCard
);
It may be your capitalization of key names. For example you have ContentType but it should be contentType as camelcase beginning with lowercase letters.
return Close(sessionAttributes,
"Fulfilled",
new LexResponse.LexMessage
{
contentType = "PlainText",
content = String.Format("Hello Kindly choose one option")
},
new LexResponse.LexResponseCard
{
version = 1,
contentType = "application/vnd.amazonaws.card.generic",
GenericAttachments =
{
new LexResponse.LexGenericAttachments
{
Buttons =
{
new LexResponse.LexButton
{
text = "Shop Now",
value = "Shop Now"
}
},
attachmentLinkUrl = null,
title = "Shopping",
subTitle = "Sub Shopping",
imageUrl = null
}
}
}
);
try just one Lex Response Card .
return Close(sessionAttributes,
"Fulfilled"
new LexResponse.LexResponseCard
{
version = 1,
contentType = "application/vnd.amazonaws.card.generic",
GenericAttachments =
{
new LexResponse.LexGenericAttachments
{
Buttons =
{
new LexResponse.LexButton
{
text = "Shop Now",
value = "Shop Now"
}
},
attachmentLinkUrl = null,
title = "Shopping",
subTitle = "Sub Shopping",
imageUrl = null
}
}
}
);
I'm trying to create a workflow where a user can do a bulk send through docusign within my application. They would select the clients they want to send forms to for a signature, be presented with a sender view to specify what fields they require, send it off, then have it post back to my application in order to generate emails for embedded signing. However, currently, it doesn't return back to my application after the user has sent off the bulk request despite the return url request being set. Is this currently not possible with a bulk send request?
The following is just some code to generate the sender view url:
// Create envelope definition
var envelopeDefinition = new EnvelopeDefinition
{
EmailSubject = documentDesc,
Documents = new List<Document>(),
Recipients = new Recipients { Signers = new List<Signer> {
new Signer
{
Name = "Multi Bulk Recipient::signer",
Email = "multiBulkRecipients-signer#docusign.com",
RoleName = "signer",
RoutingOrder = "1",
Status = "sent",
DeliveryMethod = "Email",
RecipientId = "1",
RecipientType = "signer"
}
} },
CustomFields = new CustomFields()
{
TextCustomFields = new List<TextCustomField>()
{
new TextCustomField() {Name = "Client", Value = _config.DatabaseName},
new TextCustomField() {Name = "Server", Value = _config.DatabaseServer},
new TextCustomField() {Name = "DocId", Value = documentId.ToString()}
}
},
EnvelopeIdStamping = "true",
};
// Read a file from disk to use as a document.
byte[] fileBytes = File.ReadAllBytes("test.pdf");
// Add a document to the envelope
Document doc = new Document();
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
doc.Name = "TestFile.pdf";
doc.DocumentId = "1";
envDef.Documents = new List<Document>();
envDef.Documents.Add(doc);
// Add each recipient and add them to the envelope definition
var recipients = new List<BulkSendingCopyRecipient>();
var recipients = new List<BulkSendingCopyRecipient> {
new BulkSendingCopyRecipient
{
Name = "Bob Ross",
Email = "bobross#happymistakes.com",
ClientUserId = "1234",
CustomFields = new List<string>()
{
"A custom field for internal use"
},
RoleName = "signer"
},
new BulkSendingCopyRecipient
{
Name = "Fred Rogers",
Email = "mrrogers#neighborhood.com",
ClientUserId = "5678",
CustomFields = new List<string>()
{
"Another custom field for internal use"
},
RoleName = "signer"
}
};
var bulkSendingCopy = new BulkSendingCopy
{
Recipients = recipients
};
var bulkCopies = new List<BulkSendingCopy>
{
bulkSendingCopy
};
var bulkSendingList = new BulkSendingList
{
BulkCopies = bulkCopies
};
bulkSendingList.Name = "A document name";
envelopeDefinition.Status = "created";
var envelopesApi = new EnvelopesApi(config);
var bulkEnvelopesApi = new BulkEnvelopesApi();
var createBulkListResult = bulkEnvelopesApi.CreateBulkSendList(AccountId, bulkSendingList);
envelopeDefinition.CustomFields.TextCustomFields.Add(
new TextCustomField
{
Name = "mailingListId",
Required = "false",
Show = "false",
Value = createBulkListResult.ListId //Adding the BULK_LIST_ID as an Envelope Custom Field
}
);
var envelopeSummary = envelopesApi.CreateEnvelope(AccountId, envelopeDefinition);
var options = new ReturnUrlRequest
{
ReturnUrl = HttpContext.Current.Request.Url.Scheme + "://" +
HttpContext.Current.Request.Url.Authority +
HttpContext.Current.Request.ApplicationPath +
"/SIP/ConfirmTagSendAndPublish.aspx?idockey=" + documentId
};
var senderView = envelopesApi.CreateSenderView(AccountId, envelopeSummary.EnvelopeId, options);
var senderViewInfo = new string[2];
senderViewInfo[0] = senderView.Url;
senderViewInfo[1] = envelopeSummary.EnvelopeId;
return senderViewInfo;
When the sender view comes up and you hit send it just takes me to the Sent tab in docusign
What I see after send
So in order for you to do the scenario you're asking to do, you will have to take a slightly different approach:
Generate a regular envelope in draft mode with the things you need.
Have user interact with it in embedded sending experience.
Generate a bulk using the CreateBulkList() method based on the envelope from #2 and the users you add like in your code.
(to do #3 you may need to copy custom fields etc. from the initial envelope to the one used for custom fields)
This question is an extension of my previous question.
(How can I put "AdaptiveActionSet" in "AdaptiveColumn"?)
At the time, I didn't know much about the customization of adaptive cards and the WebChat.html file.
The image above is the layout of the adaptive card I want.
The Reserve button on the right is Action.OpenUrl button.
To place a button like that, I need to put an ActionSet in a Column. However, typical Adaptive Cards do not show ActionSet in Column as in the image above.
The content type is shown below.
ContentType = "application/vnd.microsoft.card.adaptive"
(In web chat)
To solve this, I have to customize Adaptive Cards, but I'm not sure how.
(Ashamed,
I referred to the link below but still I can't customize the card.
Bot Connector service is not using latest Adaptive Cards #87
Can you show me a way to solve this or show a simple customized card example? Please.
Below is the code I wrote.
My Adaptive Cards Code :
card.Body.Add(new AdaptiveColumnSet()
{
Columns = new List<AdaptiveColumn>()
{
new AdaptiveColumn()
{
//(~Date, No problem)
},
new AdaptiveColumn()
{
//(~Price, No problem)
},
new AdaptiveColumn()
{
Items =
{
new AdaptiveActionSet()
{
Actions =
{
new AdaptiveOpenUrlAction()
{
Url = new Uri("https://www.SomeUrl.com"),
Title = "Reserve",
Style = "positive",
}
}
}
},
Width = "auto",
}
},
});
var reply = turnContext.Activity.CreateReply();
reply.Attachments = new List<Attachment>
{
new Attachment()
{
ContentType = "application/vnd.microsoft.card.custom",
Content = card
}
};
My webChat.html :
const attachmentMiddleware = () => next => card => {
if (card.attachment.contentype === 'application/vnd.microsoft.card.custom'){
card.attachment.contentType = 'application/vnd.microsoft.card.adaptive'
}
return next(card)
};
window.WebChat.renderWebChat({
directLine: botConnection,
styleOptions,
adaptiveCardHostConfig,
attachmentMiddleware
}, document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();
As above, ContentType = "application/vnd.microsoft.card.custom"
If I assign custom to contentType,
I get an error called No renderer.
Using AdaptiveColumn's SelectAction solved the problem.
And it by using AdaptiveTextBlock and SelectAction together and specifying Width.
ex)
Items =
{
new AdaptiveTextBlock()
{
HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
Color = AdaptiveTextColor.Light,
Text = "Reserve",
Weight = AdaptiveTextWeight.Bolder,
}
},
SelectAction = new AdaptiveOpenUrlAction()
{
Url = new Uri($"{someurl}"),
Title = "rsv",
Id = "bb" + cnt,
},
Width = "50px"
I have implemented a carousel of Hero Cards to display all the Schedules a perticular Doc can have. In the hero cards i have added a button to select a Particular schedule. Below is the code
private async Task ShowSessionsHeroCard(IDialogContext context)
{
var replyToConversation = context.MakeMessage();
replyToConversation.AttachmentLayout = AttachmentLayoutTypes.Carousel;
replyToConversation.Attachments = await GetSessionHeroCard(context);
//replyToConversation.Attachments.Add(GetSessionHeroCard());
await context.PostAsync(replyToConversation);
}
private async Task<List<Attachment>> GetSessionHeroCard(IDialogContext context)
{
List<Attachment> list = new List<Attachment>();
List<CardAction> cardButtons = new List<CardAction>();
foreach (var sessionDetails in scheduleList)
{
string[] session = GetSplittedDetails(sessionDetails);
hospitalName = session[0]; //Hospital Name: {0}
availableDay = session[1]; //Available Day: {1}
appointmentNo = session[2]; // Appoinment No: {2}
sessionAvailable = session[3]; // Session: {3}
HeroCard hero = new HeroCard()
{
Title = hospitalName,
Subtitle = availableDay,
Text = sessionAvailable + appointmentNo,
Buttons = cardButtons
};
list.Add(hero.ToAttachment());
}
CardAction getSessionValues = new CardAction()
{
Value = hospitalName + availableDay + sessionAvailable + appointmentNo,
Type = ActionTypes.ImBack,
Title = " Select Appointment "
};
cardButtons.Add(getSessionValues);
string selectedAppointment = getSessionValues.Value.ToString();
await GetSelectedAppointment(context, selectedAppointment);
return list;
}
private async Task GetSelectedAppointment(IDialogContext context, string sessionSelected)
{
var replyToConversation = context.MakeMessage();
//replyToConversation.AttachmentLayout = AttachmentLayoutTypes.List;
string[] result = Utility.SplitSelectedApoitmentString(sessionSelected);
var heroCard = new HeroCard()
{
Title = "Appointment Schedule",
Subtitle = "These are the Appointment Details",
Text = "Hospital selected : " + result[0] + "\n" + "Day of Appointment : " + result[1] + "\n" + "Time of Appointment : " + result[2] + "\n" + "Appointment Number" + result[3],
}.ToAttachment();
Attachment attachment = new Attachment()
{
Content = heroCard.Content,
ContentType = heroCard.ContentType
};
replyToConversation.Attachments.Add(attachment);
await context.PostAsync(replyToConversation);
}
My questions are
Am i defining the Button Correctly?
The CardAction getSessionValues is getting some values even before i click
on the button. How to avoid that.
How to get the selected card value and pass it to another method.
I cant figure out whats wrong here please help. (Am sure Am doing sumthing very stupid.)
Thanks in Advance :)
It's a bit hard to follow your code and it's not clear who is calling the GetSessionHeroCard method, however, I think you have a misunderstanding about how to work with cards.
The general steps you need to follow when using cards with buttons are:
Create the card, with the card actions
Add the card as an attachment to the reply message the bot will be sending to the user
Wait in X method (it could be on MessageReceivedAsync or in a new method) with context.Wait. This is key because this method is the one that will receive the message with the value once the button is clicked.
You can check the RichCards sample and the Contoso Flowers sample so you can see that in action.
The requirement which I have regarding docusign is I need to implement Signer Attachment and that same scenario is mentioned at [https://github.com/docusign/docusign-soap-sdk/wiki/Code-Walkthrough-_-Signer-Attachments]
But I am not sure how do I achieve with code in C#. As not sure how do I attach it to Envelope?
I want to send someone a contract letter to sign and also request them attach few docs and when all of that is completed , those docs should be sent to my email.
Anyone knows if I can achieve it with docusign?
The previous entry is not bad... I got it working eventually. But this code below is solid, in production, and works great! It also uses anchor strings.
EnvelopeDefinition env = new EnvelopeDefinition();
env.EmailSubject = "Please sign this document set";
Document doc4 = new Document
{
DocumentBase64 = doc4PdfBytes,
Name = "Voided Check Attachment", // can be different from actual file name
FileExtension = "pdf",
DocumentId = "4"
};
env.Documents = new List<Document> { doc4 };
SignerAttachment signAttachDoc = new SignerAttachment
{
TabLabel = "Attach your voided check",
DocumentId = "1",
TabId = "1",
PageNumber = "1",
AnchorString = "/at1/",
AnchorUnits = "pixels",
AnchorXOffset = "0",
AnchorYOffset = "0",
AnchorIgnoreIfNotPresent = "false",
};
Tabs signer1Tabs = new Tabs
{
SignerAttachmentTabs = new List<SignerAttachment> { signAttachDoc }
};
signer1.Tabs = signer1Tabs;
Recipients recipients1 = new Recipients
{
Signers = new List<Signer> { signer1 }
};
env.Recipients = recipients1;
Here is how we can do it while using C# SDK
create a signer object
Signer signer = new Signer();
signer.Name = recipientName;
signer.Email = recipientEmail;
signer.RecipientId = "1";
then create attachment tabs
signer.Tabs.SignerAttachmentTabs = new List<SignerAttachment>();
after which we need an attachment to add to it
SignerAttachment signDoc = new SignerAttachment();
signDoc.TabLabel = "Attach your Other Doc";
signDoc.DocumentId = "1";
signDoc.TabId = "1";
signDoc.PageNumber = "1";
And finally we add it to the tabs
signer.Tabs.SignerAttachmentTabs.Add(signDoc);