UNPKG

@microsoft/teams.api

Version:

<p> <a href="https://www.npmjs.com/package/@microsoft/teams.api" target="_blank"> <img src="https://img.shields.io/npm/v/@microsoft/teams.api/latest" /> </a> <a href="https://www.npmjs.com/package/@microsoft/teams.api?activeTab=code" t

1 lines 14.2 kB
{"version":3,"sources":["../../src/activities/activity.ts"],"names":[],"mappings":"AAwHO,MAAM,QAA4D,CAAA;AAAA;AAAA;AAAA;AAAA,EAI9D,IAAA;AAAA;AAAA;AAAA;AAAA,EAKT,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,UAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,cAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA,EAKA,IAAA;AAAA;AAAA;AAAA;AAAA,EAKA,YAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA;AAAA;AAAA;AAAA;AAAA,EAKA,QAAA;AAAA;AAAA;AAAA;AAAA,EAKA,WAAA;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,MAAS,GAAA;AACX,IAAA,OAAO,KAAK,WAAa,EAAA,MAAA;AAAA;AAC3B;AAAA;AAAA;AAAA,EAKA,IAAI,OAAU,GAAA;AACZ,IAAA,OAAO,KAAK,WAAa,EAAA,OAAA;AAAA;AAC3B;AAAA;AAAA;AAAA,EAKA,IAAI,IAAO,GAAA;AACT,IAAA,OAAO,KAAK,WAAa,EAAA,IAAA;AAAA;AAC3B;AAAA;AAAA;AAAA,EAKA,IAAI,OAAU,GAAA;AACZ,IAAA,OAAO,KAAK,WAAa,EAAA,OAAA;AAAA;AAC3B;AAAA;AAAA;AAAA,EAKA,IAAI,YAAe,GAAA;AACjB,IAAA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C,MAAM,CAAE,CAAA,IAAA,KAAS,YAAY,CAAK,IAAA,KAAA;AAAA;AAChE;AAAA;AAAA;AAAA;AAAA,EAMQ,kCAAoD,GAAA;AAC1D,IAAI,IAAA,YAAA,GAAe,KAAK,QAAU,EAAA,IAAA;AAAA,MAChC,CAAC,CAAM,KAAA,CAAA,CAAE,SAAS,4BAAgC,IAAA,CAAA,CAAE,OAAO,CAAM,KAAA;AAAA,KACnE;AAEA,IAAA,IAAI,CAAC,YAAc,EAAA;AACjB,MAAe,YAAA,GAAA;AAAA,QACb,IAAM,EAAA,4BAAA;AAAA,QACN,OAAS,EAAA,SAAA;AAAA,QACT,UAAY,EAAA,oBAAA;AAAA,QACZ,KAAO,EAAA;AAAA,OACT;AACA,MAAA,IAAA,CAAK,UAAU,YAAY,CAAA;AAAA;AAG7B,IAAO,OAAA,YAAA;AAAA;AAEX","file":"activity.mjs","sourcesContent":["import {\n Account,\n AIMessageEntity,\n ChannelData,\n ChannelID,\n ChannelInfo,\n CitationAppearance,\n CitationEntity,\n ConversationAccount,\n ConversationReference,\n Entity,\n MeetingInfo,\n MessageEntity,\n NotificationInfo,\n TeamInfo,\n} from '../models';\n\nexport interface IActivity<T extends string = string> {\n /**\n * Contains the type of the activity.\n */\n readonly type: T;\n\n /**\n * Contains an ID that uniquely identifies the activity on the channel.\n */\n id: string;\n\n /**\n * Contains the URL that specifies the channel's service endpoint. Set by the channel.\n */\n serviceUrl?: string;\n\n /**\n * Contains the date and time that the message was sent, in UTC, expressed in ISO-8601 format.\n */\n timestamp?: Date;\n\n /**\n * A locale name for the contents of the text field.\n * The locale name is a combination of an ISO 639 two- or three-letter culture code associated\n * with a language\n * and an ISO 3166 two-letter subculture code associated with a country or region.\n * The locale name can also correspond to a valid BCP-47 language tag.\n */\n locale?: string;\n\n /**\n * Contains the local date and time of the message, expressed in ISO-8601 format.\n *\n * For example, 2016-09-23T13:07:49.4714686-07:00.\n */\n localTimestamp?: Date;\n\n /**\n * Contains an ID that uniquely identifies the channel. Set by the channel.\n */\n channelId: ChannelID;\n\n /**\n * Identifies the sender of the message.\n */\n from: Account;\n\n /**\n * Identifies the conversation to which the activity belongs.\n */\n conversation: ConversationAccount;\n\n /**\n * A reference to another conversation or activity.\n */\n relatesTo?: ConversationReference;\n\n /**\n * Identifies the recipient of the message.\n */\n recipient: Account;\n\n /**\n * Contains the ID of the message to which this message is a reply.\n */\n replyToId?: string;\n\n /**\n * Represents the entities that were mentioned in the message.\n */\n entities?: Entity[];\n\n /**\n * Contains channel-specific content.\n */\n channelData?: ChannelData;\n\n /**\n * Information about the channel in which the message was sent.\n */\n get channel(): ChannelInfo | undefined;\n\n /**\n * Information about the team in which the message was sent.\n */\n get team(): TeamInfo | undefined;\n\n /**\n * Information about the tenant in which the message was sent.\n */\n get meeting(): MeetingInfo | undefined;\n\n /**\n * Notification settings for the message.\n */\n get notification(): NotificationInfo | undefined;\n\n /**\n * is this a streaming activity\n */\n isStreaming(): boolean;\n}\n\nexport class Activity<T extends string = string> implements IActivity<T> {\n /**\n * Contains the type of the activity.\n */\n readonly type!: T;\n\n /**\n * Contains an ID that uniquely identifies the activity on the channel.\n */\n id!: string;\n\n /**\n * Contains the URL that specifies the channel's service endpoint. Set by the channel.\n */\n serviceUrl?: string;\n\n /**\n * Contains the date and time that the message was sent, in UTC, expressed in ISO-8601 format.\n */\n timestamp?: Date;\n\n /**\n * A locale name for the contents of the text field.\n * The locale name is a combination of an ISO 639 two- or three-letter culture code associated\n * with a language\n * and an ISO 3166 two-letter subculture code associated with a country or region.\n * The locale name can also correspond to a valid BCP-47 language tag.\n */\n locale?: string;\n\n /**\n * Contains the local date and time of the message, expressed in ISO-8601 format.\n *\n * For example, 2016-09-23T13:07:49.4714686-07:00.\n */\n localTimestamp?: Date;\n\n /**\n * Contains an ID that uniquely identifies the channel. Set by the channel.\n */\n channelId!: ChannelID;\n\n /**\n * Identifies the sender of the message.\n */\n from!: Account;\n\n /**\n * Identifies the conversation to which the activity belongs.\n */\n conversation!: ConversationAccount;\n\n /**\n * A reference to another conversation or activity.\n */\n relatesTo?: ConversationReference;\n\n /**\n * Identifies the recipient of the message.\n */\n recipient!: Account;\n\n /**\n * Contains the ID of the message to which this message is a reply.\n */\n replyToId?: string;\n\n /**\n * Represents the entities that were mentioned in the message.\n */\n entities?: Entity[];\n\n /**\n * Contains channel-specific content.\n */\n channelData?: ChannelData;\n\n /**\n * Information about the tenant in which the message was sent.\n */\n get tenant() {\n return this.channelData?.tenant;\n }\n\n /**\n * Information about the channel in which the message was sent.\n */\n get channel() {\n return this.channelData?.channel;\n }\n\n /**\n * Information about the team in which the message was sent.\n */\n get team() {\n return this.channelData?.team;\n }\n\n /**\n * Information about the tenant in which the message was sent.\n */\n get meeting() {\n return this.channelData?.meeting;\n }\n\n /**\n * Notification settings for the message.\n */\n get notification() {\n return this.channelData?.notification;\n }\n\n constructor(value: Pick<IActivity<T>, 'type'> & Partial<Omit<IActivity<T>, 'type'>>) {\n Object.assign(this, {\n channelId: 'msteams',\n ...value,\n });\n }\n\n static from(activity: IActivity) {\n return new Activity(activity);\n }\n\n toInterface(): IActivity {\n return Object.assign({}, this);\n }\n\n clone(options: Omit<Partial<IActivity>, 'type'> = {}) {\n return new Activity({\n ...this.toInterface(),\n ...options,\n });\n }\n\n withId(value: string) {\n this.id = value;\n return this;\n }\n\n withReplyToId(value: string) {\n this.replyToId = value;\n return this;\n }\n\n withChannelId(value: ChannelID) {\n this.channelId = value;\n return this;\n }\n\n withFrom(value: Account) {\n this.from = value;\n return this;\n }\n\n withConversation(value: ConversationAccount) {\n this.conversation = value;\n return this;\n }\n\n withRelatesTo(value: ConversationReference) {\n this.relatesTo = value;\n return this;\n }\n\n withRecipient(value: Account) {\n this.recipient = value;\n return this;\n }\n\n withServiceUrl(value: string) {\n this.serviceUrl = value;\n return this;\n }\n\n withTimestamp(value: Date) {\n this.timestamp = value;\n return this;\n }\n\n withLocale(value: string) {\n this.locale = value;\n return this;\n }\n\n withLocalTimestamp(value: Date) {\n this.localTimestamp = value;\n return this;\n }\n\n withChannelData(value: ChannelData) {\n this.channelData = { ...this.channelData, ...value };\n return this;\n }\n\n /**\n * Add an entity.\n */\n addEntity(value: Entity) {\n if (!this.entities) {\n this.entities = [];\n }\n\n this.entities.push(value);\n return this;\n }\n\n /**\n * Add multiple entities\n */\n addEntities(...value: Entity[]) {\n if (!this.entities) {\n this.entities = [];\n }\n\n this.entities.push(...value);\n return this;\n }\n\n /**\n * Add the `Generated By AI` label.\n */\n addAiGenerated() {\n const messageEntity: AIMessageEntity = this.ensureSingleRootLevelMessageEntity();\n if (messageEntity.additionalType?.includes('AIGeneratedContent')) {\n return this;\n }\n\n if (!messageEntity.additionalType) {\n messageEntity.additionalType = [];\n }\n\n messageEntity.additionalType.push('AIGeneratedContent');\n return this;\n }\n\n /**\n * Enable message feedback\n */\n addFeedback() {\n if (!this.channelData) {\n this.channelData = {};\n }\n\n this.channelData.feedbackLoopEnabled = true;\n return this;\n }\n\n /**\n * Add citations\n */\n addCitation(position: number, appearance: CitationAppearance) {\n const messageEntity: CitationEntity = this.ensureSingleRootLevelMessageEntity();\n if (!messageEntity.citation) {\n messageEntity.citation = [];\n }\n\n messageEntity.citation.push({\n '@type': 'Claim',\n position,\n appearance: {\n '@type': 'DigitalDocument',\n abstract: appearance.abstract,\n name: appearance.name,\n encodingFormat: 'application/vnd.microsoft.card.adaptive',\n image: appearance.icon\n ? {\n '@type': 'ImageObject',\n name: appearance.icon,\n }\n : undefined,\n keywords: appearance.keywords,\n text: appearance.text,\n url: appearance.url,\n usageInfo: appearance.usageInfo,\n },\n });\n\n return this;\n }\n\n /**\n * is this a streaming activity\n */\n isStreaming() {\n return this.entities?.some((e) => e.type === 'streaminfo') || false;\n }\n\n /**\n * Get or create the base message entity.\n * There should only be one root level message entity.\n */\n private ensureSingleRootLevelMessageEntity(): MessageEntity {\n let mesageEntity = this.entities?.find(\n (e) => e.type === 'https://schema.org/Message' && e['@type'] === 'Message'\n ) as MessageEntity | undefined;\n\n if (!mesageEntity) {\n mesageEntity = {\n type: 'https://schema.org/Message',\n '@type': 'Message',\n '@context': 'https://schema.org',\n '@id': '',\n };\n this.addEntity(mesageEntity);\n }\n\n return mesageEntity;\n }\n}\n"]}