BotFramework-WebChat icon indicating copy to clipboard operation
BotFramework-WebChat copied to clipboard

adaptive card should render huge amount of user email and typing first 3 letters will give suggestion inside the card

Open Bradrajkumar opened this issue 7 years ago • 3 comments

hi all, i want to create an adaptive card which will render huge amount of User emailID(organizational level) and get binded in textbox in hidden format. while typing the user emailId or Name will give you the suggestion in text box.

is it possible to do?

Bradrajkumar avatar Aug 23 '19 12:08 Bradrajkumar

@Bradrajkumar Unfortunately, this is not possible with Adaptive Cards; however, you can use Web Chat's AttachmentMiddleware to render a custom attachment that has an autocomplete input field. For more details to get started, take a look at the customization Card Components Web Chat sample and the code snippets below.

Web Chat v4

const createEmailAttachmentStyleSet = ({ accent, paddingRegular }) => css({
  padding: paddingRegular,
  display: 'flex',
  flexDirection: 'column',

  '& > input': {
    flex: 1,
    marginBottom: paddingRegular
  },

  '& > div': {
    display: 'flex',

    '& > button': {
      flex: 1,
      color: accent,
      backgroundColor: 'white',
      borderStyle: 'solid',
      borderWidth: '1px',
      fontWeight: '600',
      padding: paddingRegular
    }
  }
});

const EmailAttachment = ({ emails, sendMessageBack, styleOptions }) => {
  const [value, setValue] = useState();

  const click = useCallback(() => sendMessageBack(value, value, value), [sendMessageBack, value]);
  const change = useCallback(({ target: { value: newValue }}) => setValue(newValue), [setValue]);
  const emailAttachmentStyleSet = createEmailAttachmentStyleSet(styleOptions);

  return (
    <div className={emailAttachmentStyleSet}>
      <input value={value} placeholder={'E-mail address'} onChange={change} />
      <div>
        <button className={'ac-pushButton style-default'} onClick={click}>Submit</button>
      </div>
    </div>
  )
}

const ConnectedEmailAttachment = connectToWebChat(({ sendMessageBack, styleSet: { options: styleOptions } }) => ({ sendMessageBack, styleOptions }))(EmailAttachment);

const attachmentMiddleware = () => next => card => {
  switch (card.attachment.contentType) {
    case 'application/vnd.microsoft.botframework.custom.email':
      return <ConnectedEmailAttachment emails={card.attachment.content.emails}/>;
    default:
      return next(card);
  }
};

Bot Framework SDK (Node)

this.onMessage(async context => {
    await context.sendActivity({
      attachments: [{
        content: {
          emails: ['[email protected]', '[email protected]']
        },
        contentType: 'application/vnd.microsoft.botframework.custom.email'
      }]
    });
  });

Screenshot image

For future reference, 'how to' questions such as this one are better suited for Stack Overflow. Please feel free to post other questions you have about developing your own features over there so the community at large may help out. If you need help with a Web Chat implementation, you can post a question to the Web Chat tag. Thank you!

tdurnford avatar Aug 23 '19 16:08 tdurnford

hi @tdurnford,

approach 1:- it is possible when bot framework is about to send response on webchat before that i will trigger an action which will fetch the user email from azure active directory and render all of them inside the adpative card in json format. when adaptive card rendered successfully at that time we can add some custom code for suggestion.

approach 2:-

when adative card rendered in webchat, i will click on textbox provided in adative card and type some name. That time it will trigger one action to azure AD to fetch the similar named emails.

please suggest me if any of this approach will work and help me to understand the pros and cons if neither of approach is not achievable or incorrect

Bradrajkumar avatar Oct 07 '19 06:10 Bradrajkumar

@Bradrajkumar I recommend you ask your follow up how to question on StackOverflow so the BotFramework Support Team and community at large can best assist you with your problem. Please add the Web Chat tag to your question.

tdurnford avatar Oct 07 '19 15:10 tdurnford