@microsoft/teamsfx 0.6.2-alpha.b7cedce9e.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,11 +3,9 @@ import { ConfidentialClientApplication } from '@azure/msal-node';
3
3
  import { createHash } from 'crypto';
4
4
  import { Client } from '@microsoft/microsoft-graph-client';
5
5
  import { ManagedIdentityCredential } from '@azure/identity';
6
- import { ActivityTypes, Channels, TeamsInfo, CardFactory, ActionTypes, MessageFactory, StatusCodes, verifyStateOperationName, tokenExchangeOperationName, TurnContext } from 'botbuilder';
6
+ import { ActivityTypes, Channels, TeamsInfo, CardFactory, ActionTypes, MessageFactory, StatusCodes, verifyStateOperationName, tokenExchangeOperationName } from 'botbuilder';
7
7
  import { Dialog } from 'botbuilder-dialogs';
8
8
  import { v4 } from 'uuid';
9
- import * as path from 'path';
10
- import * as fs from 'fs';
11
9
 
12
10
  // Copyright (c) Microsoft Corporation.
13
11
  // Licensed under the MIT license.
@@ -1569,873 +1567,5 @@ class TeamsFx {
1569
1567
  }
1570
1568
  }
1571
1569
 
1572
- // Copyright (c) Microsoft Corporation.
1573
- /**
1574
- * @internal
1575
- */
1576
- var ActivityType;
1577
- (function (ActivityType) {
1578
- ActivityType[ActivityType["CurrentBotInstalled"] = 0] = "CurrentBotInstalled";
1579
- ActivityType[ActivityType["CurrentBotMessaged"] = 1] = "CurrentBotMessaged";
1580
- ActivityType[ActivityType["CurrentBotUninstalled"] = 2] = "CurrentBotUninstalled";
1581
- ActivityType[ActivityType["TeamDeleted"] = 3] = "TeamDeleted";
1582
- ActivityType[ActivityType["TeamRestored"] = 4] = "TeamRestored";
1583
- ActivityType[ActivityType["CommandReceived"] = 5] = "CommandReceived";
1584
- ActivityType[ActivityType["Unknown"] = 6] = "Unknown";
1585
- })(ActivityType || (ActivityType = {}));
1586
- /**
1587
- * @internal
1588
- */
1589
- class NotificationMiddleware {
1590
- constructor(options) {
1591
- this.conversationReferenceStore = options.conversationReferenceStore;
1592
- }
1593
- async onTurn(context, next) {
1594
- const type = this.classifyActivity(context.activity);
1595
- switch (type) {
1596
- case ActivityType.CurrentBotInstalled:
1597
- case ActivityType.TeamRestored: {
1598
- const reference = TurnContext.getConversationReference(context.activity);
1599
- await this.conversationReferenceStore.set(reference);
1600
- break;
1601
- }
1602
- case ActivityType.CurrentBotMessaged: {
1603
- const reference = TurnContext.getConversationReference(context.activity);
1604
- if (!(await this.conversationReferenceStore.check(reference))) {
1605
- await this.conversationReferenceStore.set(reference);
1606
- }
1607
- break;
1608
- }
1609
- case ActivityType.CurrentBotUninstalled:
1610
- case ActivityType.TeamDeleted: {
1611
- const reference = TurnContext.getConversationReference(context.activity);
1612
- await this.conversationReferenceStore.delete(reference);
1613
- break;
1614
- }
1615
- }
1616
- await next();
1617
- }
1618
- classifyActivity(activity) {
1619
- var _a, _b;
1620
- const activityType = activity.type;
1621
- if (activityType === "installationUpdate") {
1622
- const action = (_a = activity.action) === null || _a === void 0 ? void 0 : _a.toLowerCase();
1623
- if (action === "add") {
1624
- return ActivityType.CurrentBotInstalled;
1625
- }
1626
- else {
1627
- return ActivityType.CurrentBotUninstalled;
1628
- }
1629
- }
1630
- else if (activityType === "message") {
1631
- return ActivityType.CurrentBotMessaged;
1632
- }
1633
- else if (activityType === "conversationUpdate") {
1634
- const eventType = (_b = activity.channelData) === null || _b === void 0 ? void 0 : _b.eventType;
1635
- if (eventType === "teamDeleted") {
1636
- return ActivityType.TeamDeleted;
1637
- }
1638
- else if (eventType === "teamRestored") {
1639
- return ActivityType.TeamRestored;
1640
- }
1641
- }
1642
- return ActivityType.Unknown;
1643
- }
1644
- }
1645
- class CommandResponseMiddleware {
1646
- constructor(handlers) {
1647
- this.commandHandlers = [];
1648
- if (handlers && handlers.length > 0) {
1649
- this.commandHandlers.push(...handlers);
1650
- }
1651
- }
1652
- async onTurn(context, next) {
1653
- const type = this.classifyActivity(context.activity);
1654
- let handlers = [];
1655
- switch (type) {
1656
- case ActivityType.CommandReceived:
1657
- // Invoke corresponding command handler for the command response
1658
- const commandText = this.getActivityText(context.activity);
1659
- handlers = this.filterCommandHandler(commandText, this.commandHandlers);
1660
- if (handlers.length > 0) {
1661
- const response = await handlers[0].handleCommandReceived(context, commandText);
1662
- await context.sendActivity(response);
1663
- }
1664
- break;
1665
- }
1666
- await next();
1667
- }
1668
- classifyActivity(activity) {
1669
- if (this.isCommandReceived(activity)) {
1670
- return ActivityType.CommandReceived;
1671
- }
1672
- return ActivityType.Unknown;
1673
- }
1674
- isCommandReceived(activity) {
1675
- if (this.commandHandlers) {
1676
- const commandText = this.getActivityText(activity);
1677
- const handlers = this.filterCommandHandler(commandText, this.commandHandlers);
1678
- return handlers.length > 0;
1679
- }
1680
- else {
1681
- return false;
1682
- }
1683
- }
1684
- filterCommandHandler(commandText, commandHandlers) {
1685
- const handlers = commandHandlers.filter((handler) => {
1686
- var _a;
1687
- if (typeof handler.commandNameOrPattern === "string") {
1688
- return handler.commandNameOrPattern.toLocaleLowerCase() === commandText;
1689
- }
1690
- else {
1691
- return (_a = handler.commandNameOrPattern) === null || _a === void 0 ? void 0 : _a.test(commandText);
1692
- }
1693
- });
1694
- return handlers;
1695
- }
1696
- getActivityText(activity) {
1697
- let text = activity.text;
1698
- const removedMentionText = TurnContext.removeRecipientMention(activity);
1699
- if (removedMentionText) {
1700
- text = removedMentionText
1701
- .toLowerCase()
1702
- .replace(/\n|\r\n/g, "")
1703
- .trim();
1704
- }
1705
- return text;
1706
- }
1707
- }
1708
-
1709
- // Copyright (c) Microsoft Corporation.
1710
- /**
1711
- * @internal
1712
- */
1713
- class LocalFileStorage {
1714
- constructor(fileDir) {
1715
- this.localFileName = ".notification.localstore.json";
1716
- this.filePath = path.resolve(fileDir, this.localFileName);
1717
- }
1718
- async read(key) {
1719
- if (!(await this.storeFileExists())) {
1720
- return undefined;
1721
- }
1722
- const data = await this.readFromFile();
1723
- return data[key];
1724
- }
1725
- async list() {
1726
- if (!(await this.storeFileExists())) {
1727
- return [];
1728
- }
1729
- const data = await this.readFromFile();
1730
- return Object.entries(data).map((entry) => entry[1]);
1731
- }
1732
- async write(key, object) {
1733
- if (!(await this.storeFileExists())) {
1734
- await this.writeToFile({ [key]: object });
1735
- return;
1736
- }
1737
- const data = await this.readFromFile();
1738
- await this.writeToFile(Object.assign(data, { [key]: object }));
1739
- }
1740
- async delete(key) {
1741
- if (await this.storeFileExists()) {
1742
- const data = await this.readFromFile();
1743
- if (data[key] !== undefined) {
1744
- delete data[key];
1745
- await this.writeToFile(data);
1746
- }
1747
- }
1748
- }
1749
- storeFileExists() {
1750
- return new Promise((resolve) => {
1751
- try {
1752
- fs.access(this.filePath, (err) => {
1753
- if (err) {
1754
- resolve(false);
1755
- }
1756
- else {
1757
- resolve(true);
1758
- }
1759
- });
1760
- }
1761
- catch (error) {
1762
- resolve(false);
1763
- }
1764
- });
1765
- }
1766
- readFromFile() {
1767
- return new Promise((resolve, reject) => {
1768
- try {
1769
- fs.readFile(this.filePath, { encoding: "utf-8" }, (err, rawData) => {
1770
- if (err) {
1771
- reject(err);
1772
- }
1773
- else {
1774
- resolve(JSON.parse(rawData));
1775
- }
1776
- });
1777
- }
1778
- catch (error) {
1779
- reject(error);
1780
- }
1781
- });
1782
- }
1783
- async writeToFile(data) {
1784
- return new Promise((resolve, reject) => {
1785
- try {
1786
- const rawData = JSON.stringify(data, undefined, 2);
1787
- fs.writeFile(this.filePath, rawData, { encoding: "utf-8" }, (err) => {
1788
- if (err) {
1789
- reject(err);
1790
- }
1791
- else {
1792
- resolve();
1793
- }
1794
- });
1795
- }
1796
- catch (error) {
1797
- reject(error);
1798
- }
1799
- });
1800
- }
1801
- }
1802
- /**
1803
- * @internal
1804
- */
1805
- class ConversationReferenceStore {
1806
- constructor(storage) {
1807
- this.storage = storage;
1808
- }
1809
- async check(reference) {
1810
- const ref = await this.storage.read(this.getKey(reference));
1811
- return ref !== undefined;
1812
- }
1813
- getAll() {
1814
- return this.storage.list();
1815
- }
1816
- set(reference) {
1817
- return this.storage.write(this.getKey(reference), reference);
1818
- }
1819
- delete(reference) {
1820
- return this.storage.delete(this.getKey(reference));
1821
- }
1822
- getKey(reference) {
1823
- var _a, _b;
1824
- return `_${(_a = reference.conversation) === null || _a === void 0 ? void 0 : _a.tenantId}_${(_b = reference.conversation) === null || _b === void 0 ? void 0 : _b.id}`;
1825
- }
1826
- }
1827
-
1828
- // Copyright (c) Microsoft Corporation.
1829
- // Licensed under the MIT license.
1830
- /**
1831
- * @internal
1832
- */
1833
- function cloneConversation(conversation) {
1834
- return Object.assign({}, conversation);
1835
- }
1836
- /**
1837
- * @internal
1838
- */
1839
- function getTargetType(conversationReference) {
1840
- var _a;
1841
- const conversationType = (_a = conversationReference.conversation) === null || _a === void 0 ? void 0 : _a.conversationType;
1842
- if (conversationType === "personal") {
1843
- return "Person";
1844
- }
1845
- else if (conversationType === "groupChat") {
1846
- return "Group";
1847
- }
1848
- else if (conversationType === "channel") {
1849
- return "Channel";
1850
- }
1851
- else {
1852
- return undefined;
1853
- }
1854
- }
1855
- /**
1856
- * @internal
1857
- */
1858
- function getTeamsBotInstallationId(context) {
1859
- var _a, _b, _c, _d;
1860
- return (_d = (_c = (_b = (_a = context.activity) === null || _a === void 0 ? void 0 : _a.channelData) === null || _b === void 0 ? void 0 : _b.team) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : context.activity.conversation.id;
1861
- }
1862
-
1863
- // Copyright (c) Microsoft Corporation.
1864
- /**
1865
- * Send a plain text message to a notification target.
1866
- *
1867
- * @param target - the notification target.
1868
- * @param text - the plain text message.
1869
- * @returns A `Promise` representing the asynchronous operation.
1870
- *
1871
- * @beta
1872
- */
1873
- function sendMessage(target, text) {
1874
- return target.sendMessage(text);
1875
- }
1876
- /**
1877
- * Send an adaptive card message to a notification target.
1878
- *
1879
- * @param target - the notification target.
1880
- * @param card - the adaptive card raw JSON.
1881
- * @returns A `Promise` representing the asynchronous operation.
1882
- *
1883
- * @beta
1884
- */
1885
- function sendAdaptiveCard(target, card) {
1886
- return target.sendAdaptiveCard(card);
1887
- }
1888
- /**
1889
- * A {@link NotificationTarget} that represents a team channel.
1890
- *
1891
- * @remarks
1892
- * It's recommended to get channels from {@link TeamsBotInstallation.channels()}.
1893
- *
1894
- * @beta
1895
- */
1896
- class Channel {
1897
- /**
1898
- * Constuctor.
1899
- *
1900
- * @remarks
1901
- * It's recommended to get channels from {@link TeamsBotInstallation.channels()}, instead of using this constructor.
1902
- *
1903
- * @param parent - The parent {@link TeamsBotInstallation} where this channel is created from.
1904
- * @param info - Detailed channel information.
1905
- *
1906
- * @beta
1907
- */
1908
- constructor(parent, info) {
1909
- /**
1910
- * Notification target type. For channel it's always "Channel".
1911
- *
1912
- * @beta
1913
- */
1914
- this.type = "Channel";
1915
- this.parent = parent;
1916
- this.info = info;
1917
- }
1918
- /**
1919
- * Send a plain text message.
1920
- *
1921
- * @param text - the plain text message.
1922
- * @returns A `Promise` representing the asynchronous operation.
1923
- *
1924
- * @beta
1925
- */
1926
- sendMessage(text) {
1927
- return this.parent.adapter.continueConversation(this.parent.conversationReference, async (context) => {
1928
- const conversation = await this.newConversation(context);
1929
- await this.parent.adapter.continueConversation(conversation, async (ctx) => {
1930
- await ctx.sendActivity(text);
1931
- });
1932
- });
1933
- }
1934
- /**
1935
- * Send an adaptive card message.
1936
- *
1937
- * @param card - the adaptive card raw JSON.
1938
- * @returns A `Promise` representing the asynchronous operation.
1939
- *
1940
- * @beta
1941
- */
1942
- async sendAdaptiveCard(card) {
1943
- return this.parent.adapter.continueConversation(this.parent.conversationReference, async (context) => {
1944
- const conversation = await this.newConversation(context);
1945
- await this.parent.adapter.continueConversation(conversation, async (ctx) => {
1946
- await ctx.sendActivity({
1947
- attachments: [CardFactory.adaptiveCard(card)],
1948
- });
1949
- });
1950
- });
1951
- }
1952
- /**
1953
- * @internal
1954
- */
1955
- async newConversation(context) {
1956
- const reference = TurnContext.getConversationReference(context.activity);
1957
- const channelConversation = cloneConversation(reference);
1958
- channelConversation.conversation.id = this.info.id || "";
1959
- return channelConversation;
1960
- }
1961
- }
1962
- /**
1963
- * A {@link NotificationTarget} that represents a team member.
1964
- *
1965
- * @remarks
1966
- * It's recommended to get members from {@link TeamsBotInstallation.members()}.
1967
- *
1968
- * @beta
1969
- */
1970
- class Member {
1971
- /**
1972
- * Constuctor.
1973
- *
1974
- * @remarks
1975
- * It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
1976
- *
1977
- * @param parent - The parent {@link TeamsBotInstallation} where this member is created from.
1978
- * @param account - Detailed member account information.
1979
- *
1980
- * @beta
1981
- */
1982
- constructor(parent, account) {
1983
- /**
1984
- * Notification target type. For member it's always "Person".
1985
- *
1986
- * @beta
1987
- */
1988
- this.type = "Person";
1989
- this.parent = parent;
1990
- this.account = account;
1991
- }
1992
- /**
1993
- * Send a plain text message.
1994
- *
1995
- * @param text - the plain text message.
1996
- * @returns A `Promise` representing the asynchronous operation.
1997
- *
1998
- * @beta
1999
- */
2000
- sendMessage(text) {
2001
- return this.parent.adapter.continueConversation(this.parent.conversationReference, async (context) => {
2002
- const conversation = await this.newConversation(context);
2003
- await this.parent.adapter.continueConversation(conversation, async (ctx) => {
2004
- await ctx.sendActivity(text);
2005
- });
2006
- });
2007
- }
2008
- /**
2009
- * Send an adaptive card message.
2010
- *
2011
- * @param card - the adaptive card raw JSON.
2012
- * @returns A `Promise` representing the asynchronous operation.
2013
- *
2014
- * @beta
2015
- */
2016
- async sendAdaptiveCard(card) {
2017
- return this.parent.adapter.continueConversation(this.parent.conversationReference, async (context) => {
2018
- const conversation = await this.newConversation(context);
2019
- await this.parent.adapter.continueConversation(conversation, async (ctx) => {
2020
- await ctx.sendActivity({
2021
- attachments: [CardFactory.adaptiveCard(card)],
2022
- });
2023
- });
2024
- });
2025
- }
2026
- /**
2027
- * @internal
2028
- */
2029
- async newConversation(context) {
2030
- const reference = TurnContext.getConversationReference(context.activity);
2031
- const personalConversation = cloneConversation(reference);
2032
- const connectorClient = context.turnState.get(this.parent.adapter.ConnectorClientKey);
2033
- const conversation = await connectorClient.conversations.createConversation({
2034
- isGroup: false,
2035
- tenantId: context.activity.conversation.tenantId,
2036
- bot: context.activity.recipient,
2037
- members: [this.account],
2038
- channelData: {},
2039
- });
2040
- personalConversation.conversation.id = conversation.id;
2041
- return personalConversation;
2042
- }
2043
- }
2044
- /**
2045
- * A {@link NotificationTarget} that represents a bot installation. Teams Bot could be installed into
2046
- * - Personal chat
2047
- * - Group chat
2048
- * - Team (by default the `General` channel)
2049
- *
2050
- * @remarks
2051
- * It's recommended to get bot installations from {@link ConversationBot.installations()}.
2052
- *
2053
- * @beta
2054
- */
2055
- class TeamsBotInstallation {
2056
- /**
2057
- * Constructor
2058
- *
2059
- * @remarks
2060
- * It's recommended to get bot installations from {@link ConversationBot.installations()}, instead of using this constructor.
2061
- *
2062
- * @param adapter - the bound `BotFrameworkAdapter`.
2063
- * @param conversationReference - the bound `ConversationReference`.
2064
- *
2065
- * @beta
2066
- */
2067
- constructor(adapter, conversationReference) {
2068
- this.adapter = adapter;
2069
- this.conversationReference = conversationReference;
2070
- this.type = getTargetType(conversationReference);
2071
- }
2072
- /**
2073
- * Send a plain text message.
2074
- *
2075
- * @param text - the plain text message.
2076
- * @returns A `Promise` representing the asynchronous operation.
2077
- *
2078
- * @beta
2079
- */
2080
- sendMessage(text) {
2081
- return this.adapter.continueConversation(this.conversationReference, async (context) => {
2082
- await context.sendActivity(text);
2083
- });
2084
- }
2085
- /**
2086
- * Send an adaptive card message.
2087
- *
2088
- * @param card - the adaptive card raw JSON.
2089
- * @returns A `Promise` representing the asynchronous operation.
2090
- *
2091
- * @beta
2092
- */
2093
- sendAdaptiveCard(card) {
2094
- return this.adapter.continueConversation(this.conversationReference, async (context) => {
2095
- await context.sendActivity({
2096
- attachments: [CardFactory.adaptiveCard(card)],
2097
- });
2098
- });
2099
- }
2100
- /**
2101
- * Get channels from this bot installation.
2102
- *
2103
- * @returns an array of channels if bot is installed into a team, otherwise returns an empty array.
2104
- *
2105
- * @beta
2106
- */
2107
- async channels() {
2108
- let teamsChannels = [];
2109
- await this.adapter.continueConversation(this.conversationReference, async (context) => {
2110
- const teamId = getTeamsBotInstallationId(context);
2111
- if (teamId !== undefined) {
2112
- teamsChannels = await TeamsInfo.getTeamChannels(context, teamId);
2113
- }
2114
- });
2115
- const channels = [];
2116
- for (const channel of teamsChannels) {
2117
- channels.push(new Channel(this, channel));
2118
- }
2119
- return channels;
2120
- }
2121
- /**
2122
- * Get members from this bot installation.
2123
- *
2124
- * @returns an array of members from where the bot is installed.
2125
- *
2126
- * @beta
2127
- */
2128
- async members() {
2129
- let teamsMembers = [];
2130
- await this.adapter.continueConversation(this.conversationReference, async (context) => {
2131
- teamsMembers = await TeamsInfo.getMembers(context);
2132
- });
2133
- const members = [];
2134
- for (const member of teamsMembers) {
2135
- members.push(new Member(this, member));
2136
- }
2137
- return members;
2138
- }
2139
- }
2140
- /**
2141
- * Provide static utilities for bot conversation, including
2142
- * - send notification to varies targets (e.g., member, channel, incoming wehbook)
2143
- * - handle command and response.
2144
- *
2145
- * @example
2146
- * Here's an example on how to send notification via Teams Bot.
2147
- * ```typescript
2148
- * // initialize (it's recommended to be called before handling any bot message)
2149
- * const notificationBot = new NotificationBot(adapter);
2150
- *
2151
- * // get all bot installations and send message
2152
- * for (const target of await notificationBot.installations()) {
2153
- * await target.sendMessage("Hello Notification");
2154
- * }
2155
- *
2156
- * // alternative - send message to all members
2157
- * for (const target of await notificationBot.installations()) {
2158
- * for (const member of await target.members()) {
2159
- * await member.sendMessage("Hello Notification");
2160
- * }
2161
- * }
2162
- * ```
2163
- *
2164
- * @beta
2165
- */
2166
- class NotificationBot {
2167
- /**
2168
- * constructor of the notification bot.
2169
- *
2170
- * @remarks
2171
- * To ensure accuracy, it's recommended to initialize before handling any message.
2172
- *
2173
- * @param adapter - the bound `BotFrameworkAdapter`
2174
- * @param options - initialize options
2175
- *
2176
- * @beta
2177
- */
2178
- constructor(adapter, options) {
2179
- var _a, _b;
2180
- const storage = (_a = options === null || options === void 0 ? void 0 : options.storage) !== null && _a !== void 0 ? _a : new LocalFileStorage(path.resolve(process.env.RUNNING_ON_AZURE === "1" ? (_b = process.env.TEMP) !== null && _b !== void 0 ? _b : "./" : "./"));
2181
- this.conversationReferenceStore = new ConversationReferenceStore(storage);
2182
- this.adapter = adapter.use(new NotificationMiddleware({
2183
- conversationReferenceStore: this.conversationReferenceStore,
2184
- }));
2185
- }
2186
- /**
2187
- * Get all targets where the bot is installed.
2188
- *
2189
- * @remarks
2190
- * The result is retrieving from the persisted storage.
2191
- *
2192
- * @returns - an array of {@link TeamsBotInstallation}.
2193
- *
2194
- * @beta
2195
- */
2196
- async installations() {
2197
- if (this.conversationReferenceStore === undefined || this.adapter === undefined) {
2198
- throw new Error("NotificationBot has not been initialized.");
2199
- }
2200
- const references = (await this.conversationReferenceStore.getAll()).values();
2201
- const targets = [];
2202
- for (const reference of references) {
2203
- // validate connection
2204
- let valid = true;
2205
- this.adapter.continueConversation(reference, async (context) => {
2206
- try {
2207
- // try get member to see if the installation is still valid
2208
- await TeamsInfo.getPagedMembers(context, 1);
2209
- }
2210
- catch (error) {
2211
- if (error.code === "BotNotInConversationRoster") {
2212
- valid = false;
2213
- }
2214
- }
2215
- });
2216
- if (valid) {
2217
- targets.push(new TeamsBotInstallation(this.adapter, reference));
2218
- }
2219
- else {
2220
- this.conversationReferenceStore.delete(reference);
2221
- }
2222
- }
2223
- return targets;
2224
- }
2225
- }
2226
-
2227
- // Copyright (c) Microsoft Corporation.
2228
- /**
2229
- * A command bot for receiving commands and sending responses in Teams.
2230
- *
2231
- * @remarks
2232
- * Ensure each command should ONLY be registered with the command once, otherwise it'll cause unexpected behavior if you register the same command more than once.
2233
- *
2234
- * @example
2235
- * You can register your commands through the constructor of the {@link CommandBot}, or use the `registerCommand` and `registerCommands` API to add commands after creating the `CommandBot` instance.
2236
- *
2237
- * ```typescript
2238
- * // register through constructor
2239
- * const commandBot = new CommandBot(adapter, [ new HelloWorldCommandHandler() ]);
2240
- *
2241
- * // register through `register*` API
2242
- * commandBot.registerCommand(new HelpCommandHandler());
2243
- * ```
2244
- *
2245
- * @beta
2246
- */
2247
- class CommandBot {
2248
- /**
2249
- * Creates a new instance of the `CommandBot`.
2250
- *
2251
- * @param adapter The bound `BotFrameworkAdapter`.
2252
- * @param commands The commands to registered with the command bot. Each command should implement the interface {@link TeamsFxBotCommandHandler} so that it can be correctly handled by this command bot.
2253
- *
2254
- * @beta
2255
- */
2256
- constructor(adapter, commands) {
2257
- this.middleware = new CommandResponseMiddleware(commands);
2258
- this.adapter = adapter.use(this.middleware);
2259
- }
2260
- /**
2261
- * Registers a command into the command bot.
2262
- *
2263
- * @param command The command to registered.
2264
- *
2265
- * @beta
2266
- */
2267
- registerCommand(command) {
2268
- if (command) {
2269
- this.middleware.commandHandlers.push(command);
2270
- }
2271
- }
2272
- /**
2273
- * Registers commands into the command bot.
2274
- *
2275
- * @param commands The command to registered.
2276
- *
2277
- * @beta
2278
- */
2279
- registerCommands(commands) {
2280
- if (commands) {
2281
- this.middleware.commandHandlers.push(...commands);
2282
- }
2283
- }
2284
- }
2285
-
2286
- // Copyright (c) Microsoft Corporation.
2287
- const { AdaptiveCards } = require("@microsoft/adaptivecards-tools");
2288
- /**
2289
- * Provides utility method to build bot message with cards that supported in Teams.
2290
- */
2291
- class MessageBuilder {
2292
- /**
2293
- * Build a bot message activity attached with adaptive card.
2294
- *
2295
- * @param getCardData Function to prepare your card data.
2296
- * @param cardTemplate The adaptive card template.
2297
- * @returns A bot message activity attached with an adaptive card.
2298
- *
2299
- * @example
2300
- * ```javascript
2301
- * const cardTemplate = {
2302
- * type: "AdaptiveCard",
2303
- * body: [
2304
- * {
2305
- * "type": "TextBlock",
2306
- * "text": "${title}",
2307
- * "size": "Large"
2308
- * },
2309
- * {
2310
- * "type": "TextBlock",
2311
- * "text": "${description}"
2312
- * }],
2313
- * $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
2314
- * version: "1.4"
2315
- * };
2316
- *
2317
- * type CardData = {
2318
- * title: string,
2319
- * description: string
2320
- * };
2321
- * const card = MessageBuilder.attachAdaptiveCard<CardData>(() => {
2322
- * return {
2323
- * title: "sample card title",
2324
- * description: "sample card description"
2325
- * }}, cardTemplate);
2326
- * ```
2327
- *
2328
- * @beta
2329
- */
2330
- static attachAdaptiveCard(getCardData, cardTemplate) {
2331
- const cardData = getCardData();
2332
- return {
2333
- attachments: [CardFactory.adaptiveCard(AdaptiveCards.declare(cardTemplate).render(cardData))],
2334
- };
2335
- }
2336
- /**
2337
- * Build a bot message activity attached with an adaptive card.
2338
- *
2339
- * @param card The adaptive card content.
2340
- * @returns A bot message activity attached with an adaptive card.
2341
- *
2342
- * @beta
2343
- */
2344
- static attachAdaptiveCardWithoutData(card) {
2345
- return {
2346
- attachments: [CardFactory.adaptiveCard(AdaptiveCards.declareWithoutData(card).render())],
2347
- };
2348
- }
2349
- /**
2350
- * Build a bot message activity attached with an hero card.
2351
- *
2352
- * @param title The card title.
2353
- * @param images Optional. The array of images to include on the card.
2354
- * @param buttons Optional. The array of buttons to include on the card. Each `string` in the array
2355
- * is converted to an `imBack` button with a title and value set to the value of the string.
2356
- * @param other Optional. Any additional properties to include on the card.
2357
- *
2358
- * @returns A bot message activity attached with a hero card.
2359
- *
2360
- * @example
2361
- * ```javascript
2362
- * const message = MessageBuilder.attachHeroCard(
2363
- * 'sample title',
2364
- * ['https://example.com/sample.jpg'],
2365
- * ['action']
2366
- * );
2367
- * ```
2368
- *
2369
- * @beta
2370
- */
2371
- static attachHeroCard(title, images, buttons, other) {
2372
- return MessageBuilder.attachContent(CardFactory.heroCard(title, images, buttons, other));
2373
- }
2374
- /**
2375
- * Returns an attachment for a sign-in card.
2376
- *
2377
- * @param title The title for the card's sign-in button.
2378
- * @param url The URL of the sign-in page to use.
2379
- * @param text Optional. Additional text to include on the card.
2380
- *
2381
- * @returns A bot message activity attached with a sign-in card.
2382
- *
2383
- * @remarks
2384
- * For channels that don't natively support sign-in cards, an alternative message is rendered.
2385
- *
2386
- * @beta
2387
- */
2388
- static attachSigninCard(title, url, text) {
2389
- return MessageBuilder.attachContent(CardFactory.signinCard(title, url, text));
2390
- }
2391
- /**
2392
- * Build a bot message activity attached with an Office 365 connector card.
2393
- *
2394
- * @param card A description of the Office 365 connector card.
2395
- * @returns A bot message activity attached with an Office 365 connector card.
2396
- *
2397
- * @beta
2398
- */
2399
- static attachO365ConnectorCard(card) {
2400
- return MessageBuilder.attachContent(CardFactory.o365ConnectorCard(card));
2401
- }
2402
- /**
2403
- * Build a message activity attached with a receipt card.
2404
- * @param card A description of the receipt card.
2405
- * @returns A message activity attached with a receipt card.
2406
- *
2407
- * @beta
2408
- */
2409
- static AttachReceiptCard(card) {
2410
- return MessageBuilder.attachContent(CardFactory.receiptCard(card));
2411
- }
2412
- /**
2413
- *
2414
- * @param title The card title.
2415
- * @param images Optional. The array of images to include on the card.
2416
- * @param buttons Optional. The array of buttons to include on the card. Each `string` in the array
2417
- * is converted to an `imBack` button with a title and value set to the value of the string.
2418
- * @param other Optional. Any additional properties to include on the card.
2419
- * @returns A message activity attached with a thumbnail card
2420
- *
2421
- * @beta
2422
- */
2423
- static attachThumbnailCard(title, images, buttons, other) {
2424
- return MessageBuilder.attachContent(CardFactory.thumbnailCard(title, images, buttons, other));
2425
- }
2426
- /**
2427
- * Add an attachement to a bot activity.
2428
- * @param attachement The attachment object to attach.
2429
- * @returns A message activity with an attachment.
2430
- *
2431
- * @beta
2432
- */
2433
- static attachContent(attachement) {
2434
- return {
2435
- attachments: [attachement],
2436
- };
2437
- }
2438
- }
2439
-
2440
- export { AppCredential, Channel, CommandBot, ErrorCode, ErrorWithCode, IdentityType, LogLevel, Member, MessageBuilder, MsGraphAuthProvider, NotificationBot, OnBehalfOfUserCredential, TeamsBotInstallation, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createMicrosoftGraphClient, getLogLevel, getTediousConnectionConfig, sendAdaptiveCard, sendMessage, setLogFunction, setLogLevel, setLogger };
1570
+ export { AppCredential, ErrorCode, ErrorWithCode, IdentityType, LogLevel, MsGraphAuthProvider, OnBehalfOfUserCredential, TeamsBotSsoPrompt, TeamsFx, TeamsUserCredential, createMicrosoftGraphClient, getLogLevel, getTediousConnectionConfig, setLogFunction, setLogLevel, setLogger };
2441
1571
  //# sourceMappingURL=index.esm2017.mjs.map