diff --git a/apps/teams-test-app/src/components/AppAPIs.tsx b/apps/teams-test-app/src/components/AppAPIs.tsx index c7da2095ed..4b0c411ebb 100644 --- a/apps/teams-test-app/src/components/AppAPIs.tsx +++ b/apps/teams-test-app/src/components/AppAPIs.tsx @@ -20,6 +20,7 @@ const GetContext = (): ReactElement => onClick: { withPromise: async () => { const context = await app.getContext(); + console.log('This is the context: ' + context); return JSON.stringify(context); }, withCallback: (setResult) => { diff --git a/apps/teams-test-app/src/components/privateApis/ExternalAppCardActionsForCEAAPIs.tsx b/apps/teams-test-app/src/components/privateApis/ExternalAppCardActionsForCEAAPIs.tsx index 165fb8249b..9fb6477695 100644 --- a/apps/teams-test-app/src/components/privateApis/ExternalAppCardActionsForCEAAPIs.tsx +++ b/apps/teams-test-app/src/components/privateApis/ExternalAppCardActionsForCEAAPIs.tsx @@ -35,8 +35,13 @@ const ProcessActionSubmitForCEA = (): React.ReactElement => } }, submit: async (input) => { + console.log(`Potential app id (${input.appId}) prints like this`); + const objectAppId = new AppId(input.appId); + console.log(`objectAppId app id (${objectAppId}) prints like this`); + await externalAppCardActionsForCEA.processActionSubmit( - new AppId(input.appId), + new AppId(objectAppId as unknown as string), + input.conversationId, input.actionSubmitPayload, ); diff --git a/packages/teams-js/src/internal/constants.ts b/packages/teams-js/src/internal/constants.ts index b3679e7ac7..63f4b90416 100644 --- a/packages/teams-js/src/internal/constants.ts +++ b/packages/teams-js/src/internal/constants.ts @@ -1,4 +1,5 @@ import * as validOriginsJSON from '../artifactsForCDN/validDomains.json'; +import { ApiName } from './telemetry'; /** * @hidden @@ -177,3 +178,5 @@ export const errorRuntimeNotSupported = 'The runtime version is not supported'; /** @hidden */ export const errorCallNotStarted = 'The call was not properly started'; + +export const reportTelemetryBackToHost = [ApiName.Copilot_Eligibility_GetEligibilityInfo]; diff --git a/packages/teams-js/src/internal/handlers.ts b/packages/teams-js/src/internal/handlers.ts index 2613d474a6..5146a0b6f4 100644 --- a/packages/teams-js/src/internal/handlers.ts +++ b/packages/teams-js/src/internal/handlers.ts @@ -5,7 +5,8 @@ import { FrameContexts } from '../public/constants'; import { HostToAppPerformanceMetrics, LoadContext, ResumeContext } from '../public/interfaces'; import * as pages from '../public/pages/pages'; import { runtime } from '../public/runtime'; -import { Communication, sendMessageEventToChild, sendMessageToParent } from './communication'; +import { callFunctionInHost, Communication, sendMessageEventToChild, sendMessageToParent } from './communication'; +import { reportTelemetryBackToHost } from './constants'; import { ensureInitialized } from './internalAPIs'; import { getLogger } from './telemetry'; import { isNullOrUndefined } from './typeCheckUtilities'; @@ -198,12 +199,36 @@ export function registerHostToAppPerformanceMetricsHandler( * Limited to Microsoft-internal use */ export function handleHostToAppPerformanceMetrics(metrics: HostToAppPerformanceMetrics): void { + console.log('NOW IT WILL CHECK WHETHER THE HANDLER IS REGISTERED OR NOT --> ' + metrics.actionName); + // post the metrics to the parent window without using async/await. That will make sure the metric is posted asynchronously, + // and does not stop the response to go to the calling app. + // IF we don't want to post back everything, we can add a check here to see if the API name is copilot.eligibility + shouldSendTelemetryBack(metrics.actionName as ApiName) && + callFunctionInHost( + 'reportTelemetryEvent', + [metrics.actionName, metrics.actionId, metrics.messageDelay, metrics.requestStartedAt], + 'v3_reportTelemetryEvent', + ); + if (!HandlersPrivate.hostToAppPerformanceMetricsHandler) { return; } HandlersPrivate.hostToAppPerformanceMetricsHandler(metrics); } +/** + * @internal + * Limited to Microsoft-internal use + * + * @hidden + */ +function shouldSendTelemetryBack(actionName: ApiName): boolean { + console.log('NOW IT WILL CHECK the action name --> ' + actionName); + console.log( + 'NOW IT WILL decide whether to post it back to hub sdk --> ' + reportTelemetryBackToHost.includes(actionName), + ); + return reportTelemetryBackToHost.includes(actionName); +} /** * @internal * Limited to Microsoft-internal use diff --git a/packages/teams-js/src/internal/hostToAppTelemetry.ts b/packages/teams-js/src/internal/hostToAppTelemetry.ts index 3340dc3ce3..576e175115 100644 --- a/packages/teams-js/src/internal/hostToAppTelemetry.ts +++ b/packages/teams-js/src/internal/hostToAppTelemetry.ts @@ -56,6 +56,7 @@ export default class HostToAppMessageDelayTelemetry { } handleHostToAppPerformanceMetrics({ actionName: message.func, + actionId: message.uuid?.toString() || 'theUuidOfMessageIsNotAvailable', messageDelay: endTime - timestamp, requestStartedAt: timestamp, }); @@ -86,8 +87,12 @@ export default class HostToAppMessageDelayTelemetry { ); return; } + console.log('callbackInformation', callbackInformation); + console.log('message', message); + //the api call should always reach here regardless the handler is registered or not handleHostToAppPerformanceMetrics({ actionName: callbackInformation.name, + actionId: callbackID.toString(), messageDelay: endTime - message.monotonicTimestamp, requestStartedAt: callbackInformation.calledAt, }); diff --git a/packages/teams-js/src/public/interfaces.ts b/packages/teams-js/src/public/interfaces.ts index 8f10629bb5..55dd559c46 100644 --- a/packages/teams-js/src/public/interfaces.ts +++ b/packages/teams-js/src/public/interfaces.ts @@ -1312,6 +1312,8 @@ export interface ClipboardParams { export interface HostToAppPerformanceMetrics { /** The name of the action the host is responding to. */ actionName: string; + /** The Id of the message from what the response was received */ + actionId: string; /** The delay the message took traveling from host to app */ messageDelay: number; /** The time when the request was dispatched */