libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py
def fill_qna_event(
        self,
        query_results: [QueryResult],
        turn_context: TurnContext,
        telemetry_properties: Dict[str,str] = None,
        telemetry_metrics: Dict[str,float] = None
    ) -> EventData:
        """
        Fills the event properties and metrics for the QnaMessage event for telemetry.

        :return: A tuple of event data properties and metrics that will be sent to the BotTelemetryClient.track_event() method for the QnAMessage event. The properties and metrics returned the standard properties logged with any properties passed from the get_answers() method.

        :rtype: EventData
        """

        properties: Dict[str,str] = dict()
        metrics: Dict[str, float] = dict()

        properties[QnATelemetryConstants.knowledge_base_id_property] = self._endpoint.knowledge_base_id

        text: str = turn_context.activity.text
        userName: str = turn_context.activity.from_property.name

        # Use the LogPersonalInformation flag to toggle logging PII data; text and username are common examples.
        if self.log_personal_information:
            if text:
                properties[QnATelemetryConstants.question_property] = text
            
            if userName:
                properties[QnATelemetryConstants.username_property] = userName

        # Fill in Qna Results (found or not).
        if len(query_results) > 0:
            query_result = query_results[0]

            result_properties = {
                QnATelemetryConstants.matched_question_property: json.dumps(query_result.questions),
                QnATelemetryConstants.question_id_property: str(query_result.id),
                QnATelemetryConstants.answer_property: query_result.answer,
                QnATelemetryConstants.score_metric: query_result.score,
                QnATelemetryConstants.article_found_property: 'true'
            }

            properties.update(result_properties)
        else:
            no_match_properties = {
                QnATelemetryConstants.matched_question_property : 'No Qna Question matched',
                QnATelemetryConstants.question_id_property : 'No Qna Question Id matched',
                QnATelemetryConstants.answer_property : 'No Qna Answer matched',
                QnATelemetryConstants.article_found_property : 'false'
            }
            
            properties.update(no_match_properties)

        # Additional Properties can override "stock" properties.
        if telemetry_properties:
            properties.update(telemetry_properties)

        # Additional Metrics can override "stock" metrics.
        if telemetry_metrics:
            metrics.update(telemetry_metrics)
        
        return EventData(properties=properties, metrics=metrics)
def fill_qna_event(
        self,
        query_results: [QueryResult],
        turn_context: TurnContext,
        telemetry_properties: Dict[str,str] = None,
        telemetry_metrics: Dict[str,float] = None
    ) -> EventData:
        """
        Fills the event properties and metrics for the QnaMessage event for telemetry.

        :return: A tuple of event data properties and metrics that will be sent to the BotTelemetryClient.track_event() method for the QnAMessage event. The properties and metrics returned the standard properties logged with any properties passed from the get_answers() method.

        :rtype: EventData
        """

        properties: Dict[str,str] = dict()
        metrics: Dict[str, float] = dict()

        properties[QnATelemetryConstants.knowledge_base_id_property] = self._endpoint.knowledge_base_id

        text: str = turn_context.activity.text
        userName: str = turn_context.activity.from_property.name

        # Use the LogPersonalInformation flag to toggle logging PII data; text and username are common examples.
        if self.log_personal_information:
            if text:
                properties[QnATelemetryConstants.question_property] = text
            
            if userName:
                properties[QnATelemetryConstants.username_property] = userName

        # Fill in Qna Results (found or not).
        if len(query_results) > 0:
            query_result = query_results[0]

            result_properties = {
                QnATelemetryConstants.matched_question_property: json.dumps(query_result.questions),
                QnATelemetryConstants.question_id_property: str(query_result.id),
                QnATelemetryConstants.answer_property: query_result.answer,
                QnATelemetryConstants.score_metric: query_result.score,
                QnATelemetryConstants.article_found_property: 'true'
            }

            properties.update(result_properties)
        else:
            no_match_properties = {
                QnATelemetryConstants.matched_question_property : 'No Qna Question matched',
                QnATelemetryConstants.question_id_property : 'No Qna Question Id matched',
                QnATelemetryConstants.answer_property : 'No Qna Answer matched',
                QnATelemetryConstants.article_found_property : 'false'
            }
            
            properties.update(no_match_properties)

        # Additional Properties can override "stock" properties.
        if telemetry_properties:
            properties.update(telemetry_properties)

        # Additional Metrics can override "stock" metrics.
        if telemetry_metrics:
            metrics.update(telemetry_metrics)
        
        return EventData(properties=properties, metrics=metrics)
Fills the event properties and metrics for the QnaMessage event for telemetry.

        :return: A tuple of event data properties and metrics that will be sent to the BotTelemetryClient.track_event() method for the QnAMessage event. The properties and metrics returned the standard properties logged with any properties passed from the get_answers() method.

        :rtype: EventData