File size: 1,189 Bytes
0827183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from typing import Dict

from botbuilder.ai.luis import LuisRecognizer, LuisTelemetryConstants
from botbuilder.core import RecognizerResult, TurnContext


class TelemetryOverrideRecognizer(LuisRecognizer):
    def __init__(self, *args, **kwargs):
        super(TelemetryOverrideRecognizer, self).__init__(*args, **kwargs)

    def on_recognizer_result(
        self,
        recognizer_result: RecognizerResult,
        turn_context: TurnContext,
        telemetry_properties: Dict[str, str] = None,
        telemetry_metrics: Dict[str, float] = None,
    ):
        if "MyImportantProperty" not in telemetry_properties:
            telemetry_properties["MyImportantProperty"] = "myImportantValue"

        # Log event
        self.telemetry_client.track_event(
            LuisTelemetryConstants.luis_result, telemetry_properties, telemetry_metrics
        )

        # Create second event.
        second_event_properties: Dict[str, str] = {
            "MyImportantProperty2": "myImportantValue2"
        }
        self.telemetry_client.track_event("MySecondEvent", second_event_properties)