-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20bcabb
commit 1f83796
Showing
6 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
apps/teams-test-app/src/components/privateApis/ExternalAppCardActionsForCECAPIs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { externalAppCardActions } from '@microsoft/teams-js'; | ||
import React from 'react'; | ||
|
||
import { ApiWithoutInput, ApiWithTextInput } from '../utils'; | ||
import { ModuleWrapper } from '../utils/ModuleWrapper'; | ||
|
||
const CheckExternalAppCardActionsCapability = (): React.ReactElement => | ||
ApiWithoutInput({ | ||
name: 'checkExternalAppCardActionsCapability', | ||
title: 'Check External App Card Actions Capability', | ||
onClick: async () => | ||
`External App Card Actions module ${externalAppCardActions.isSupported() ? 'is' : 'is not'} supported`, | ||
}); | ||
|
||
const ProcessActionSubmit = (): React.ReactElement => | ||
ApiWithTextInput<{ | ||
appId: string; | ||
actionSubmitPayload: externalAppCardActions.IAdaptiveCardActionSubmit; | ||
}>({ | ||
name: 'processActionSubmit', | ||
title: 'Process Action Submit', | ||
onClick: { | ||
validateInput: (input) => { | ||
if (!input.appId) { | ||
throw new Error('appId is required'); | ||
} | ||
if (!input.actionSubmitPayload) { | ||
throw new Error('actionSubmitPayload is required'); | ||
} | ||
}, | ||
submit: async (input) => { | ||
await externalAppCardActions.processActionSubmit(input.appId, input.actionSubmitPayload); | ||
return 'Completed'; | ||
}, | ||
}, | ||
defaultInput: JSON.stringify({ | ||
appId: 'b7f8c0a0-6c1d-4a9a-9c0a-2c3f1c0a3b0a', | ||
actionSubmitPayload: { | ||
id: 'submitId', | ||
data: 'data1', | ||
}, | ||
}), | ||
}); | ||
|
||
const ProcessActionOpenUrl = (): React.ReactElement => | ||
ApiWithTextInput<{ | ||
appId: string; | ||
url: string; | ||
fromElement?: { name: 'composeExtensions' | 'plugins' }; | ||
}>({ | ||
name: 'processActionOpenUrl', | ||
title: 'Process Action Open Url', | ||
onClick: { | ||
validateInput: (input) => { | ||
if (!input.appId) { | ||
throw new Error('appId is required'); | ||
} | ||
if (!input.url) { | ||
throw new Error('url is required'); | ||
} | ||
}, | ||
submit: async (input) => { | ||
const result = await externalAppCardActions.processActionOpenUrl( | ||
input.appId, | ||
new URL(input.url), | ||
input.fromElement, | ||
); | ||
return JSON.stringify(result); | ||
}, | ||
}, | ||
defaultInput: JSON.stringify({ | ||
appId: 'b7f8c0a0-6c1d-4a9a-9c0a-2c3f1c0a3b0a', | ||
url: 'https://www.example.com', | ||
}), | ||
}); | ||
|
||
const ExternalAppCardActionsForCECAPIs = (): React.ReactElement => ( | ||
<ModuleWrapper title="External App Card Actions"> | ||
<CheckExternalAppCardActionsCapability /> | ||
<ProcessActionSubmit /> | ||
<ProcessActionOpenUrl /> | ||
</ModuleWrapper> | ||
); | ||
|
||
export default ExternalAppCardActionsForCECAPIs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/teams-js/src/private/externalAppCardActionsForCEC.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { sendMessageToParentAsync } from '../internal/communication'; | ||
import { ensureInitialized } from '../internal/internalAPIs'; | ||
import { ApiName, ApiVersionNumber, getApiVersionTag } from '../internal/telemetry'; | ||
import { validateId } from '../internal/utils'; | ||
import { errorNotSupportedOnPlatform, FrameContexts } from '../public/constants'; | ||
import { runtime } from '../public/runtime'; | ||
import { externalAppCardActions } from './externalAppCardActions'; | ||
|
||
/** | ||
* Updated to constants file: v2 APIs telemetry file: All of APIs in this capability file should send out API version v2 ONLY | ||
*/ | ||
const externalAppCardActionsTelemetryVersionNumber: ApiVersionNumber = ApiVersionNumber.V_2; | ||
|
||
export namespace externalAppCardActionsForCEC { | ||
export function processActionOpenUrl( | ||
appId: string, | ||
conversationId: string, | ||
url: URL, | ||
): Promise<externalAppCardActions.ActionOpenUrlType> { | ||
ensureInitialized(runtime, FrameContexts.content); | ||
|
||
if (!isSupported()) { | ||
throw errorNotSupportedOnPlatform; | ||
} | ||
validateId(appId, new Error('App id is not valid.')); | ||
return sendMessageToParentAsync< | ||
[externalAppCardActions.ActionOpenUrlError, externalAppCardActions.ActionOpenUrlType] | ||
>( | ||
getApiVersionTag( | ||
externalAppCardActionsTelemetryVersionNumber, | ||
ApiName.ExternalAppCardActions_ProcessActionOpenUrl, | ||
), | ||
'externalAppCardActions.cec.processActionOpenUrl', | ||
[appId, url.href, conversationId], | ||
).then( | ||
([error, response]: [externalAppCardActions.ActionOpenUrlError, externalAppCardActions.ActionOpenUrlType]) => { | ||
if (error) { | ||
throw error; | ||
} else { | ||
return response; | ||
} | ||
}, | ||
); | ||
} | ||
|
||
export function processActionSubmit( | ||
appId: string, | ||
conversationId: string, | ||
actionSubmitPayload: externalAppCardActions.IAdaptiveCardActionSubmit, // alternatively, we can move IAdaptiveCardActionSubmit to interface | ||
): Promise<void> { | ||
ensureInitialized(runtime, FrameContexts.content); | ||
|
||
if (!isSupported()) { | ||
throw errorNotSupportedOnPlatform; | ||
} | ||
validateId(appId, new Error('App id is not valid.')); | ||
|
||
return sendMessageToParentAsync<[boolean, externalAppCardActions.ActionSubmitError]>( | ||
getApiVersionTag( | ||
externalAppCardActionsTelemetryVersionNumber, | ||
ApiName.ExternalAppCardActions_ProcessActionSubmit, | ||
), | ||
'externalAppCardActions.cec.processActionSubmit', | ||
[appId, conversationId, actionSubmitPayload], | ||
).then(([wasSuccessful, error]: [boolean, externalAppCardActions.ActionSubmitError]) => { | ||
if (!wasSuccessful) { | ||
throw error; | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* @hidden | ||
* Checks if the externalAppCardActions capability is supported by the host | ||
* @returns boolean to represent whether externalAppCardActions capability is supported | ||
* | ||
* @throws Error if {@linkcode app.initialize} has not successfully completed | ||
* | ||
* @internal | ||
* Limited to Microsoft-internal use | ||
*/ | ||
export function isSupported(): boolean { | ||
return ensureInitialized(runtime) && runtime.supports.externalAppCardActionsForCEC ? true : false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters