Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export createAttachmentMiddleware to reduce changes for custom middlewares provided by hosts #564

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bkebede252
Copy link

@bkebede252 bkebede252 commented Dec 17, 2024

Thank you for your contribution. Before submitting this PR, please include:

Id of the task, bug, story or other reference.

Description

Include a description of the problem to be solved

  • We were trying to create a custom attachmentmiddleware, it seems that if we copy the current code we'd miss out on future implementations. By exporting the createAttachmentmiddleware, we can wrap custom code on top of the default attachmentmiddleware. Here is a sample code :

import { createAttachmentMiddleware } from '@microsoft/omnichannel-chat-widget'

const customAttachmentMiddleware =
() =>
() =>
(next: any) =>
(...args: any) => {
// set custom code here to return custom component or logic before triggering default attachment middleware
const [card] = args
if (!card?.activity) {
return next(...args)
}

  const {
    activity: { attachments },
    attachment,
  }: { activity: { attachments: any }; attachment: any } = card
  // No attachment
  if (!attachments || !attachments.length || !attachment) {
    return next(...args)
  }

  // Check for Adaptive cards
  // eslint-disable-next-line prefer-const
  let { content, contentType } = attachment || { content: '', contentType: '' }
  let { type } = content || { type: '' }

  if (type === 'AdaptiveCard' || contentType === 'application/vnd.microsoft.card.adaptive') { 
    return <SampleComponent attachment={ attachment }/>
  }

  // end of custom code 
  // default attachment middleware from omnichannel-chat-widget
  return createAttachmentMiddleware(enableInlinePlaying)()(next)(...args)
}

Solution Proposed

Detail what is the solution proposed, include links to design document if required or any other document required to support the solution

  • Export createAttachmentMiddleware

Acceptance criteria

Define what are the conditions to consider the PR has achieved the intended goal

Test cases and evidence

Include what tests cases were considered, any evidence of testing for future references, to identify any corner cases, etc

Sanity Tests

  • You have tested all changes in Popout mode
  • You have tested all changes in cross browsers i.e Edge, Chrome, Firefox, Safari and mobile devices(iOS and Android)
  • Your changes are included in the CHANGELOG

A11y

Please provide justification if any of the validations has been skipped.

@bkebede252 bkebede252 requested a review from a team as a code owner December 17, 2024 00:05
@bkebede252
Copy link
Author

@microsoft-github-policy-service agree company="Microsoft"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant