From 498d3d2e749ba582e1e2859634783e5f0d1129d2 Mon Sep 17 00:00:00 2001 From: Lakhveer Kaur Date: Tue, 3 Dec 2024 11:48:31 -0800 Subject: [PATCH 1/3] send eleigibility data to hubsdk to log telemetry --- apps/teams-test-app/src/components/AppAPIs.tsx | 1 + packages/teams-js/src/internal/handlers.ts | 13 ++++++++++++- .../teams-js/src/internal/hostToAppTelemetry.ts | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) 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/packages/teams-js/src/internal/handlers.ts b/packages/teams-js/src/internal/handlers.ts index 2613d474a6..344eb7db7e 100644 --- a/packages/teams-js/src/internal/handlers.ts +++ b/packages/teams-js/src/internal/handlers.ts @@ -5,7 +5,7 @@ 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 { ensureInitialized } from './internalAPIs'; import { getLogger } from './telemetry'; import { isNullOrUndefined } from './typeCheckUtilities'; @@ -198,9 +198,20 @@ export function registerHostToAppPerformanceMetricsHandler( * Limited to Microsoft-internal use */ export function handleHostToAppPerformanceMetrics(metrics: HostToAppPerformanceMetrics): void { + console.log('NOW IT WILL CHEKCK WHETHER THE HANDLER IS REGISTERED OR NOT'); + // 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 + callFunctionInHost( + 'reportTelemetryEvent', + [metrics.actionName, metrics.messageDelay, metrics.requestStartedAt], + 'v3_reportTelemetryEvent', + ); if (!HandlersPrivate.hostToAppPerformanceMetricsHandler) { + console.log('not registered'); return; } + console.log('registered'); HandlersPrivate.hostToAppPerformanceMetricsHandler(metrics); } diff --git a/packages/teams-js/src/internal/hostToAppTelemetry.ts b/packages/teams-js/src/internal/hostToAppTelemetry.ts index 80d58d2d40..e701b7eed2 100644 --- a/packages/teams-js/src/internal/hostToAppTelemetry.ts +++ b/packages/teams-js/src/internal/hostToAppTelemetry.ts @@ -86,6 +86,9 @@ 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, messageDelay: endTime - message.monotonicTimestamp, From e6fb05cb72cadfc0b902b1f8716c94804ce1b9fe Mon Sep 17 00:00:00 2001 From: Lakhveer Kaur Date: Thu, 19 Dec 2024 09:46:44 -0800 Subject: [PATCH 2/3] adding more paramters --- .../privateApis/ExternalAppCardActionsForCEAAPIs.tsx | 7 ++++++- packages/teams-js/src/internal/handlers.ts | 4 ++-- packages/teams-js/src/internal/hostToAppTelemetry.ts | 2 ++ packages/teams-js/src/public/interfaces.ts | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) 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/handlers.ts b/packages/teams-js/src/internal/handlers.ts index 344eb7db7e..fc2b819d77 100644 --- a/packages/teams-js/src/internal/handlers.ts +++ b/packages/teams-js/src/internal/handlers.ts @@ -198,13 +198,13 @@ export function registerHostToAppPerformanceMetricsHandler( * Limited to Microsoft-internal use */ export function handleHostToAppPerformanceMetrics(metrics: HostToAppPerformanceMetrics): void { - console.log('NOW IT WILL CHEKCK WHETHER THE HANDLER IS REGISTERED OR NOT'); + 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 callFunctionInHost( 'reportTelemetryEvent', - [metrics.actionName, metrics.messageDelay, metrics.requestStartedAt], + [metrics.actionName, metrics.actionId, metrics.messageDelay, metrics.requestStartedAt], 'v3_reportTelemetryEvent', ); if (!HandlersPrivate.hostToAppPerformanceMetricsHandler) { diff --git a/packages/teams-js/src/internal/hostToAppTelemetry.ts b/packages/teams-js/src/internal/hostToAppTelemetry.ts index e701b7eed2..298260868c 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, }); @@ -91,6 +92,7 @@ export default class HostToAppMessageDelayTelemetry { //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 */ From 3cddeb5a273d2ea34b12fbb142a451e327420f30 Mon Sep 17 00:00:00 2001 From: Lakhveer Kaur Date: Tue, 21 Jan 2025 14:26:31 -0800 Subject: [PATCH 3/3] make call just for eligibility api --- packages/teams-js/src/internal/constants.ts | 3 +++ packages/teams-js/src/internal/handlers.ts | 28 +++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) 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 fc2b819d77..5146a0b6f4 100644 --- a/packages/teams-js/src/internal/handlers.ts +++ b/packages/teams-js/src/internal/handlers.ts @@ -6,6 +6,7 @@ import { HostToAppPerformanceMetrics, LoadContext, ResumeContext } from '../publ import * as pages from '../public/pages/pages'; import { runtime } from '../public/runtime'; import { callFunctionInHost, Communication, sendMessageEventToChild, sendMessageToParent } from './communication'; +import { reportTelemetryBackToHost } from './constants'; import { ensureInitialized } from './internalAPIs'; import { getLogger } from './telemetry'; import { isNullOrUndefined } from './typeCheckUtilities'; @@ -202,19 +203,32 @@ export function handleHostToAppPerformanceMetrics(metrics: HostToAppPerformanceM // 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 - callFunctionInHost( - 'reportTelemetryEvent', - [metrics.actionName, metrics.actionId, metrics.messageDelay, metrics.requestStartedAt], - 'v3_reportTelemetryEvent', - ); + shouldSendTelemetryBack(metrics.actionName as ApiName) && + callFunctionInHost( + 'reportTelemetryEvent', + [metrics.actionName, metrics.actionId, metrics.messageDelay, metrics.requestStartedAt], + 'v3_reportTelemetryEvent', + ); + if (!HandlersPrivate.hostToAppPerformanceMetricsHandler) { - console.log('not registered'); return; } - console.log('registered'); 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