Spaces:
Build error
Build error
File size: 2,459 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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from datetime import datetime
from botbuilder.schema import (
Activity,
ActivityTypes,
ChannelAccount,
ConversationAccount,
)
class ActivityUtil:
@staticmethod
def create_trace(
turn_activity: Activity,
name: str,
value: object = None,
value_type: str = None,
label: str = None,
) -> Activity:
"""Creates a trace activity based on this activity.
:param turn_activity:
:type turn_activity: Activity
:param name: The value to assign to the trace activity's <see cref="Activity.name"/> property.
:type name: str
:param value: The value to assign to the trace activity's <see cref="Activity.value"/> property., defaults
to None
:param value: object, optional
:param value_type: The value to assign to the trace activity's <see cref="Activity.value_type"/> property,
defaults to None
:param value_type: str, optional
:param label: The value to assign to the trace activity's <see cref="Activity.label"/> property, defaults
to None
:param label: str, optional
:return: The created trace activity.
:rtype: Activity
"""
from_property = (
ChannelAccount(
id=turn_activity.recipient.id, name=turn_activity.recipient.name
)
if turn_activity.recipient is not None
else ChannelAccount()
)
if value_type is None and value is not None:
value_type = type(value).__name__
reply = Activity(
type=ActivityTypes.trace,
timestamp=datetime.utcnow(),
from_property=from_property,
recipient=ChannelAccount(
id=turn_activity.from_property.id, name=turn_activity.from_property.name
),
reply_to_id=turn_activity.id,
service_url=turn_activity.service_url,
channel_id=turn_activity.channel_id,
conversation=ConversationAccount(
is_group=turn_activity.conversation.is_group,
id=turn_activity.conversation.id,
name=turn_activity.conversation.name,
),
name=name,
label=label,
value_type=value_type,
value=value,
)
return reply
|