@microsoft/teamsfx 0.6.3-alpha.266fa3b9f.0 → 0.6.3-alpha.6b8bcebfe.0

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.
@@ -63,6 +63,7 @@ export declare class ApiKeyProvider implements AuthProvider {
63
63
  * @param { ApiKeyLocation } keyLocation - The location of API Key: request header or query parameter.
64
64
  *
65
65
  * @throws {@link ErrorCode|InvalidParameter} - when key name or key value is empty.
66
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
66
67
  *
67
68
  * @beta
68
69
  */
@@ -76,6 +77,7 @@ export declare class ApiKeyProvider implements AuthProvider {
76
77
  * @returns Updated axios request config.
77
78
  *
78
79
  * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when API key already exists in request header or url query parameter.
80
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
79
81
  *
80
82
  * @beta
81
83
  */
@@ -229,6 +231,7 @@ export declare class BasicAuthProvider implements AuthProvider {
229
231
  * @param { string } password - Password used in basic auth
230
232
  *
231
233
  * @throws {@link ErrorCode|InvalidParameter} - when username or password is empty.
234
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
232
235
  *
233
236
  * @beta
234
237
  */
@@ -242,6 +245,7 @@ export declare class BasicAuthProvider implements AuthProvider {
242
245
  * @returns Updated axios request config.
243
246
  *
244
247
  * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header or auth property already exists in request configuration.
248
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
245
249
  *
246
250
  * @beta
247
251
  */
@@ -676,1279 +680,1283 @@ export declare function createMicrosoftGraphClient(teamsfx: TeamsFxConfiguration
676
680
  *
677
681
  * @param { string | Buffer } cert - The cert chain in PEM format
678
682
  * @param { string | Buffer } key - The private key for the cert chain
679
- * @param { string? } passphrase - The passphrase for private key
680
- * @param { string? | Buffer? } ca - Overrides the trusted CA certificates
683
+ * @param { {passphrase?: string; ca?: string | Buffer} } options - Optional settings when create the cert options.
684
+ *
685
+ * @returns Instance of SecureContextOptions
686
+ *
687
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
688
+ *
689
+ */
690
+ export declare function createPemCertOption(cert: string | Buffer, key: string | Buffer, options?: {
691
+ passphrase?: string;
692
+ ca?: string | Buffer;
693
+ }): SecureContextOptions;
694
+
695
+ /**
696
+ * Helper to create SecureContextOptions from PFX format cert
697
+ *
698
+ * @param { string | Buffer } pfx - The content of .pfx file
699
+ * @param { {passphrase?: string} } options - Optional settings when create the cert options.
700
+ *
701
+ * @returns Instance of SecureContextOptions
702
+ *
703
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
704
+ *
705
+ */
706
+ export declare function createPfxCertOption(pfx: string | Buffer, options?: {
707
+ passphrase?: string;
708
+ }): SecureContextOptions;
709
+
710
+ /**
711
+ * Error code to trace the error types.
712
+ * @beta
713
+ */
714
+ export declare enum ErrorCode {
715
+ /**
716
+ * Invalid parameter error.
717
+ */
718
+ InvalidParameter = "InvalidParameter",
719
+ /**
720
+ * Invalid configuration error.
721
+ */
722
+ InvalidConfiguration = "InvalidConfiguration",
723
+ /**
724
+ * Invalid certificate error.
725
+ */
726
+ InvalidCertificate = "InvalidCertificate",
727
+ /**
728
+ * Internal error.
729
+ */
730
+ InternalError = "InternalError",
731
+ /**
732
+ * Channel is not supported error.
733
+ */
734
+ ChannelNotSupported = "ChannelNotSupported",
735
+ /**
736
+ * Runtime is not supported error.
737
+ */
738
+ RuntimeNotSupported = "RuntimeNotSupported",
739
+ /**
740
+ * User failed to finish the AAD consent flow failed.
741
+ */
742
+ ConsentFailed = "ConsentFailed",
743
+ /**
744
+ * The user or administrator has not consented to use the application error.
745
+ */
746
+ UiRequiredError = "UiRequiredError",
747
+ /**
748
+ * Token is not within its valid time range error.
749
+ */
750
+ TokenExpiredError = "TokenExpiredError",
751
+ /**
752
+ * Call service (AAD or simple authentication server) failed.
753
+ */
754
+ ServiceError = "ServiceError",
755
+ /**
756
+ * Operation failed.
757
+ */
758
+ FailedOperation = "FailedOperation",
759
+ /**
760
+ * Invalid response error.
761
+ */
762
+ InvalidResponse = "InvalidResponse",
763
+ /**
764
+ * Identity type error.
765
+ */
766
+ IdentityTypeNotSupported = "IdentityTypeNotSupported",
767
+ /**
768
+ * Authentication info already exists error.
769
+ */
770
+ AuthorizationInfoAlreadyExists = "AuthorizationInfoAlreadyExists"
771
+ }
772
+
773
+ /**
774
+ * Error class with code and message thrown by the SDK.
775
+ *
776
+ * @beta
777
+ */
778
+ export declare class ErrorWithCode extends Error {
779
+ /**
780
+ * Error code
681
781
  *
682
- * @returns Instance of SecureContextOptions
782
+ * @readonly
783
+ */
784
+ code: string | undefined;
785
+ /**
786
+ * Constructor of ErrorWithCode.
683
787
  *
684
- * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
788
+ * @param {string} message - error message.
789
+ * @param {ErrorCode} code - error code.
685
790
  *
791
+ * @beta
686
792
  */
687
- export declare function createPemCertOption(cert: string | Buffer, key: string | Buffer, passphrase?: string, ca?: string | Buffer): SecureContextOptions;
688
-
689
- /**
690
- * Helper to create SecureContextOptions from PFX format cert
691
- *
692
- * @param { string | Buffer } pfx - The content of .pfx file
693
- * @param { string? } passphrase - Optional. The passphrase of .pfx file
694
- *
695
- * @returns Instance of SecureContextOptions
696
- *
697
- * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
698
- *
699
- */
700
- export declare function createPfxCertOption(pfx: string | Buffer, passphrase?: string): SecureContextOptions;
701
-
702
- /**
703
- * Error code to trace the error types.
704
- * @beta
705
- */
706
- export declare enum ErrorCode {
707
- /**
708
- * Invalid parameter error.
709
- */
710
- InvalidParameter = "InvalidParameter",
711
- /**
712
- * Invalid configuration error.
713
- */
714
- InvalidConfiguration = "InvalidConfiguration",
715
- /**
716
- * Invalid certificate error.
717
- */
718
- InvalidCertificate = "InvalidCertificate",
719
- /**
720
- * Internal error.
721
- */
722
- InternalError = "InternalError",
723
- /**
724
- * Channel is not supported error.
725
- */
726
- ChannelNotSupported = "ChannelNotSupported",
727
- /**
728
- * Runtime is not supported error.
729
- */
730
- RuntimeNotSupported = "RuntimeNotSupported",
731
- /**
732
- * User failed to finish the AAD consent flow failed.
733
- */
734
- ConsentFailed = "ConsentFailed",
735
- /**
736
- * The user or administrator has not consented to use the application error.
737
- */
738
- UiRequiredError = "UiRequiredError",
739
- /**
740
- * Token is not within its valid time range error.
741
- */
742
- TokenExpiredError = "TokenExpiredError",
743
- /**
744
- * Call service (AAD or simple authentication server) failed.
745
- */
746
- ServiceError = "ServiceError",
747
- /**
748
- * Operation failed.
749
- */
750
- FailedOperation = "FailedOperation",
751
- /**
752
- * Invalid response error.
753
- */
754
- InvalidResponse = "InvalidResponse",
755
- /**
756
- * Identity type error.
757
- */
758
- IdentityTypeNotSupported = "IdentityTypeNotSupported",
759
- /**
760
- * Authentication info already exists error.
761
- */
762
- AuthorizationInfoAlreadyExists = "AuthorizationInfoAlreadyExists"
763
- }
764
-
765
- /**
766
- * Error class with code and message thrown by the SDK.
767
- *
768
- * @beta
769
- */
770
- export declare class ErrorWithCode extends Error {
771
- /**
772
- * Error code
773
- *
774
- * @readonly
775
- */
776
- code: string | undefined;
777
- /**
778
- * Constructor of ErrorWithCode.
779
- *
780
- * @param {string} message - error message.
781
- * @param {ErrorCode} code - error code.
782
- *
783
- * @beta
784
- */
785
- constructor(message?: string, code?: ErrorCode);
786
- }
787
-
788
- /**
789
- * Get log level.
790
- *
791
- * @returns Log level
792
- *
793
- * @beta
794
- */
795
- export declare function getLogLevel(): LogLevel | undefined;
796
-
797
- /**
798
- * Generate connection configuration consumed by tedious.
799
- *
800
- * @param {TeamsFx} teamsfx - Used to provide configuration and auth
801
- * @param { string? } databaseName - specify database name to override default one if there are multiple databases.
802
- *
803
- * @returns Connection configuration of tedious for the SQL.
804
- *
805
- * @throws {@link ErrorCode|InvalidConfiguration} when SQL config resource configuration is invalid.
806
- * @throws {@link ErrorCode|InternalError} when get user MSI token failed or MSI token is invalid.
807
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
808
- *
809
- * @beta
810
- */
811
- export declare function getTediousConnectionConfig(teamsfx: TeamsFx, databaseName?: string): Promise<ConnectionConfig>;
812
-
813
- /**
814
- * Identity type to use in authentication.
815
- *
816
- * @beta
817
- */
818
- export declare enum IdentityType {
819
- /**
820
- * Represents the current user of Teams.
821
- */
822
- User = "User",
823
- /**
824
- * Represents the application itself.
825
- */
826
- App = "Application"
827
- }
828
-
829
- /**
830
- * Log function for customized logging.
831
- *
832
- * @beta
833
- */
834
- export declare type LogFunction = (level: LogLevel, message: string) => void;
793
+ constructor(message?: string, code?: ErrorCode);
794
+ }
835
795
 
836
- /**
837
- * Interface for customized logger.
838
- * @beta
839
- */
840
- export declare interface Logger {
841
- /**
842
- * Writes to error level logging or lower.
843
- */
844
- error(message: string): void;
845
- /**
846
- * Writes to warning level logging or lower.
847
- */
848
- warn(message: string): void;
849
- /**
850
- * Writes to info level logging or lower.
851
- */
852
- info(message: string): void;
853
- /**
854
- * Writes to verbose level logging.
855
- */
856
- verbose(message: string): void;
857
- }
796
+ /**
797
+ * Get log level.
798
+ *
799
+ * @returns Log level
800
+ *
801
+ * @beta
802
+ */
803
+ export declare function getLogLevel(): LogLevel | undefined;
858
804
 
859
- /**
860
- * Log level.
861
- *
862
- * @beta
863
- */
864
- export declare enum LogLevel {
865
- /**
866
- * Show verbose, information, warning and error message.
867
- */
868
- Verbose = 0,
869
- /**
870
- * Show information, warning and error message.
871
- */
872
- Info = 1,
873
- /**
874
- * Show warning and error message.
875
- */
876
- Warn = 2,
877
- /**
878
- * Show error message.
879
- */
880
- Error = 3
881
- }
805
+ /**
806
+ * Generate connection configuration consumed by tedious.
807
+ *
808
+ * @param {TeamsFx} teamsfx - Used to provide configuration and auth
809
+ * @param { string? } databaseName - specify database name to override default one if there are multiple databases.
810
+ *
811
+ * @returns Connection configuration of tedious for the SQL.
812
+ *
813
+ * @throws {@link ErrorCode|InvalidConfiguration} when SQL config resource configuration is invalid.
814
+ * @throws {@link ErrorCode|InternalError} when get user MSI token failed or MSI token is invalid.
815
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
816
+ *
817
+ * @beta
818
+ */
819
+ export declare function getTediousConnectionConfig(teamsfx: TeamsFx, databaseName?: string): Promise<ConnectionConfig>;
882
820
 
883
- /**
884
- * A {@link NotificationTarget} that represents a team member.
885
- *
886
- * @remarks
887
- * It's recommended to get members from {@link TeamsBotInstallation.members()}.
888
- *
889
- * @beta
890
- */
891
- export declare class Member implements NotificationTarget {
892
- /**
893
- * The parent {@link TeamsBotInstallation} where this member is created from.
894
- *
895
- * @beta
896
- */
897
- readonly parent: TeamsBotInstallation;
898
- /**
899
- * Detailed member account information.
900
- *
901
- * @beta
902
- */
903
- readonly account: TeamsChannelAccount;
904
- /**
905
- * Notification target type. For member it's always "Person".
906
- *
907
- * @beta
908
- */
909
- readonly type: NotificationTargetType;
910
- /**
911
- * Constuctor.
912
- *
913
- * @remarks
914
- * It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
915
- *
916
- * @param parent - The parent {@link TeamsBotInstallation} where this member is created from.
917
- * @param account - Detailed member account information.
918
- *
919
- * @beta
920
- */
921
- constructor(parent: TeamsBotInstallation, account: TeamsChannelAccount);
922
- /**
923
- * Send a plain text message.
924
- *
925
- * @param text - the plain text message.
926
- * @returns A `Promise` representing the asynchronous operation.
927
- *
928
- * @beta
929
- */
930
- sendMessage(text: string): Promise<void>;
931
- /**
932
- * Send an adaptive card message.
933
- *
934
- * @param card - the adaptive card raw JSON.
935
- * @returns A `Promise` representing the asynchronous operation.
936
- *
937
- * @beta
938
- */
939
- sendAdaptiveCard(card: unknown): Promise<void>;
940
- /**
941
- * @internal
942
- */
943
- private newConversation;
944
- }
821
+ /**
822
+ * Identity type to use in authentication.
823
+ *
824
+ * @beta
825
+ */
826
+ export declare enum IdentityType {
827
+ /**
828
+ * Represents the current user of Teams.
829
+ */
830
+ User = "User",
831
+ /**
832
+ * Represents the application itself.
833
+ */
834
+ App = "Application"
835
+ }
945
836
 
946
- /**
947
- * Provides utility method to build bot message with cards that supported in Teams.
948
- */
949
- export declare class MessageBuilder {
950
- /**
951
- * Build a bot message activity attached with adaptive card.
952
- *
953
- * @param cardTemplate The adaptive card template.
954
- * @param data card data used to render the template.
955
- * @returns A bot message activity attached with an adaptive card.
956
- *
957
- * @example
958
- * ```javascript
959
- * const cardTemplate = {
960
- * type: "AdaptiveCard",
961
- * body: [
962
- * {
963
- * "type": "TextBlock",
964
- * "text": "${title}",
965
- * "size": "Large"
966
- * },
967
- * {
968
- * "type": "TextBlock",
969
- * "text": "${description}"
970
- * }],
971
- * $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
972
- * version: "1.4"
973
- * };
974
- *
975
- * type CardData = {
976
- * title: string,
977
- * description: string
978
- * };
979
- * const card = MessageBuilder.attachAdaptiveCard<CardData>(
980
- * cardTemplate, {
981
- * title: "sample card title",
982
- * description: "sample card description"
983
- * });
984
- * ```
985
- *
986
- * @beta
987
- */
988
- static attachAdaptiveCard<TData>(cardTemplate: any, data: TData): Partial<Activity_2>;
989
- /**
990
- * Build a bot message activity attached with an adaptive card.
991
- *
992
- * @param card The adaptive card content.
993
- * @returns A bot message activity attached with an adaptive card.
994
- *
995
- * @beta
996
- */
997
- static attachAdaptiveCardWithoutData(card: any): Partial<Activity_2>;
998
- /**
999
- * Build a bot message activity attached with an hero card.
1000
- *
1001
- * @param title The card title.
1002
- * @param images Optional. The array of images to include on the card.
1003
- * @param buttons Optional. The array of buttons to include on the card. Each `string` in the array
1004
- * is converted to an `imBack` button with a title and value set to the value of the string.
1005
- * @param other Optional. Any additional properties to include on the card.
1006
- *
1007
- * @returns A bot message activity attached with a hero card.
1008
- *
1009
- * @example
1010
- * ```javascript
1011
- * const message = MessageBuilder.attachHeroCard(
1012
- * 'sample title',
1013
- * ['https://example.com/sample.jpg'],
1014
- * ['action']
1015
- * );
1016
- * ```
1017
- *
1018
- * @beta
1019
- */
1020
- static attachHeroCard(title: string, images?: (CardImage | string)[], buttons?: (CardAction | string)[], other?: Partial<HeroCard>): Partial<Activity_2>;
1021
- /**
1022
- * Returns an attachment for a sign-in card.
1023
- *
1024
- * @param title The title for the card's sign-in button.
1025
- * @param url The URL of the sign-in page to use.
1026
- * @param text Optional. Additional text to include on the card.
1027
- *
1028
- * @returns A bot message activity attached with a sign-in card.
1029
- *
1030
- * @remarks
1031
- * For channels that don't natively support sign-in cards, an alternative message is rendered.
1032
- *
1033
- * @beta
1034
- */
1035
- static attachSigninCard(title: string, url: string, text?: string): Partial<Activity_2>;
1036
- /**
1037
- * Build a bot message activity attached with an Office 365 connector card.
1038
- *
1039
- * @param card A description of the Office 365 connector card.
1040
- * @returns A bot message activity attached with an Office 365 connector card.
1041
- *
1042
- * @beta
1043
- */
1044
- static attachO365ConnectorCard(card: O365ConnectorCard): Partial<Activity_2>;
1045
- /**
1046
- * Build a message activity attached with a receipt card.
1047
- * @param card A description of the receipt card.
1048
- * @returns A message activity attached with a receipt card.
1049
- *
1050
- * @beta
1051
- */
1052
- static AttachReceiptCard(card: ReceiptCard): Partial<Activity_2>;
1053
- /**
1054
- *
1055
- * @param title The card title.
1056
- * @param images Optional. The array of images to include on the card.
1057
- * @param buttons Optional. The array of buttons to include on the card. Each `string` in the array
1058
- * is converted to an `imBack` button with a title and value set to the value of the string.
1059
- * @param other Optional. Any additional properties to include on the card.
1060
- * @returns A message activity attached with a thumbnail card
1061
- *
1062
- * @beta
1063
- */
1064
- static attachThumbnailCard(title: string, images?: (CardImage | string)[], buttons?: (CardAction | string)[], other?: Partial<ThumbnailCard>): Partial<Activity_2>;
1065
- /**
1066
- * Add an attachement to a bot activity.
1067
- * @param attachement The attachment object to attach.
1068
- * @returns A message activity with an attachment.
1069
- *
1070
- * @beta
1071
- */
1072
- static attachContent(attachement: Attachment): Partial<Activity_2>;
1073
- }
837
+ /**
838
+ * Log function for customized logging.
839
+ *
840
+ * @beta
841
+ */
842
+ export declare type LogFunction = (level: LogLevel, message: string) => void;
1074
843
 
1075
- /**
1076
- * Microsoft Graph auth provider for Teams Framework
1077
- *
1078
- * @beta
1079
- */
1080
- export declare class MsGraphAuthProvider implements AuthenticationProvider {
1081
- private teamsfx;
1082
- private scopes;
1083
- /**
1084
- * Constructor of MsGraphAuthProvider.
1085
- *
1086
- * @param {TeamsFx} teamsfx - Used to provide configuration and auth.
1087
- * @param {string | string[]} scopes - The list of scopes for which the token will have access.
1088
- *
1089
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1090
- *
1091
- * @returns An instance of MsGraphAuthProvider.
1092
- *
1093
- * @beta
1094
- */
1095
- constructor(teamsfx: TeamsFxConfiguration, scopes?: string | string[]);
1096
- /**
1097
- * Get access token for Microsoft Graph API requests.
1098
- *
1099
- * @throws {@link ErrorCode|InternalError} when get access token failed due to empty token or unknown other problems.
1100
- * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
1101
- * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
1102
- * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth or AAD server.
1103
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1104
- *
1105
- * @returns Access token from the credential.
1106
- *
1107
- */
1108
- getAccessToken(): Promise<string>;
1109
- }
844
+ /**
845
+ * Interface for customized logger.
846
+ * @beta
847
+ */
848
+ export declare interface Logger {
849
+ /**
850
+ * Writes to error level logging or lower.
851
+ */
852
+ error(message: string): void;
853
+ /**
854
+ * Writes to warning level logging or lower.
855
+ */
856
+ warn(message: string): void;
857
+ /**
858
+ * Writes to info level logging or lower.
859
+ */
860
+ info(message: string): void;
861
+ /**
862
+ * Writes to verbose level logging.
863
+ */
864
+ verbose(message: string): void;
865
+ }
1110
866
 
1111
- /**
1112
- * Provide utilities to send notification to varies targets (e.g., member, group, channel).
1113
- *
1114
- * @beta
1115
- */
1116
- export declare class NotificationBot {
1117
- private readonly conversationReferenceStore;
1118
- private readonly adapter;
1119
- /**
1120
- * constructor of the notification bot.
1121
- *
1122
- * @remarks
1123
- * To ensure accuracy, it's recommended to initialize before handling any message.
1124
- *
1125
- * @param adapter - the bound `BotFrameworkAdapter`
1126
- * @param options - initialize options
1127
- *
1128
- * @beta
1129
- */
1130
- constructor(adapter: BotFrameworkAdapter, options?: NotificationOptions_2);
1131
- /**
1132
- * Get all targets where the bot is installed.
1133
- *
1134
- * @remarks
1135
- * The result is retrieving from the persisted storage.
1136
- *
1137
- * @returns - an array of {@link TeamsBotInstallation}.
1138
- *
1139
- * @beta
1140
- */
1141
- installations(): Promise<TeamsBotInstallation[]>;
1142
- }
867
+ /**
868
+ * Log level.
869
+ *
870
+ * @beta
871
+ */
872
+ export declare enum LogLevel {
873
+ /**
874
+ * Show verbose, information, warning and error message.
875
+ */
876
+ Verbose = 0,
877
+ /**
878
+ * Show information, warning and error message.
879
+ */
880
+ Info = 1,
881
+ /**
882
+ * Show warning and error message.
883
+ */
884
+ Warn = 2,
885
+ /**
886
+ * Show error message.
887
+ */
888
+ Error = 3
889
+ }
1143
890
 
1144
- /**
1145
- * Options to initialize {@link NotificationBot}.
1146
- *
1147
- * @beta
1148
- */
1149
- declare interface NotificationOptions_2 {
1150
- /**
1151
- * An optional storage to persist bot notification connections.
1152
- *
1153
- * @remarks
1154
- * If `storage` is not provided, a default local file storage will be used,
1155
- * which stores notification connections into:
1156
- * - ".notification.localstore.json" if running locally
1157
- * - "${process.env.TEMP}/.notification.localstore.json" if `process.env.RUNNING_ON_AZURE` is set to "1"
1158
- *
1159
- * It's recommended to use your own shared storage for production environment.
1160
- *
1161
- * @beta
1162
- */
1163
- storage?: NotificationTargetStorage;
1164
- }
1165
- export { NotificationOptions_2 as NotificationOptions }
891
+ /**
892
+ * A {@link NotificationTarget} that represents a team member.
893
+ *
894
+ * @remarks
895
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}.
896
+ *
897
+ * @beta
898
+ */
899
+ export declare class Member implements NotificationTarget {
900
+ /**
901
+ * The parent {@link TeamsBotInstallation} where this member is created from.
902
+ *
903
+ * @beta
904
+ */
905
+ readonly parent: TeamsBotInstallation;
906
+ /**
907
+ * Detailed member account information.
908
+ *
909
+ * @beta
910
+ */
911
+ readonly account: TeamsChannelAccount;
912
+ /**
913
+ * Notification target type. For member it's always "Person".
914
+ *
915
+ * @beta
916
+ */
917
+ readonly type: NotificationTargetType;
918
+ /**
919
+ * Constuctor.
920
+ *
921
+ * @remarks
922
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
923
+ *
924
+ * @param parent - The parent {@link TeamsBotInstallation} where this member is created from.
925
+ * @param account - Detailed member account information.
926
+ *
927
+ * @beta
928
+ */
929
+ constructor(parent: TeamsBotInstallation, account: TeamsChannelAccount);
930
+ /**
931
+ * Send a plain text message.
932
+ *
933
+ * @param text - the plain text message.
934
+ * @returns A `Promise` representing the asynchronous operation.
935
+ *
936
+ * @beta
937
+ */
938
+ sendMessage(text: string): Promise<void>;
939
+ /**
940
+ * Send an adaptive card message.
941
+ *
942
+ * @param card - the adaptive card raw JSON.
943
+ * @returns A `Promise` representing the asynchronous operation.
944
+ *
945
+ * @beta
946
+ */
947
+ sendAdaptiveCard(card: unknown): Promise<void>;
948
+ /**
949
+ * @internal
950
+ */
951
+ private newConversation;
952
+ }
1166
953
 
1167
- /**
1168
- * Represent a notification target.
1169
- *
1170
- * @beta
1171
- */
1172
- export declare interface NotificationTarget {
1173
- /**
1174
- * The type of target, could be "Channel" or "Group" or "Person".
1175
- *
1176
- * @beta
1177
- */
1178
- readonly type?: NotificationTargetType;
1179
- /**
1180
- * Send a plain text message.
1181
- *
1182
- * @param text - the plain text message.
1183
- *
1184
- * @beta
1185
- */
1186
- sendMessage(text: string): Promise<void>;
1187
- /**
1188
- * Send an adaptive card message.
1189
- *
1190
- * @param card - the adaptive card raw JSON.
1191
- *
1192
- * @beta
1193
- */
1194
- sendAdaptiveCard(card: unknown): Promise<void>;
1195
- }
954
+ /**
955
+ * Provides utility method to build bot message with cards that supported in Teams.
956
+ */
957
+ export declare class MessageBuilder {
958
+ /**
959
+ * Build a bot message activity attached with adaptive card.
960
+ *
961
+ * @param cardTemplate The adaptive card template.
962
+ * @param data card data used to render the template.
963
+ * @returns A bot message activity attached with an adaptive card.
964
+ *
965
+ * @example
966
+ * ```javascript
967
+ * const cardTemplate = {
968
+ * type: "AdaptiveCard",
969
+ * body: [
970
+ * {
971
+ * "type": "TextBlock",
972
+ * "text": "${title}",
973
+ * "size": "Large"
974
+ * },
975
+ * {
976
+ * "type": "TextBlock",
977
+ * "text": "${description}"
978
+ * }],
979
+ * $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
980
+ * version: "1.4"
981
+ * };
982
+ *
983
+ * type CardData = {
984
+ * title: string,
985
+ * description: string
986
+ * };
987
+ * const card = MessageBuilder.attachAdaptiveCard<CardData>(
988
+ * cardTemplate, {
989
+ * title: "sample card title",
990
+ * description: "sample card description"
991
+ * });
992
+ * ```
993
+ *
994
+ * @beta
995
+ */
996
+ static attachAdaptiveCard<TData>(cardTemplate: any, data: TData): Partial<Activity_2>;
997
+ /**
998
+ * Build a bot message activity attached with an adaptive card.
999
+ *
1000
+ * @param card The adaptive card content.
1001
+ * @returns A bot message activity attached with an adaptive card.
1002
+ *
1003
+ * @beta
1004
+ */
1005
+ static attachAdaptiveCardWithoutData(card: any): Partial<Activity_2>;
1006
+ /**
1007
+ * Build a bot message activity attached with an hero card.
1008
+ *
1009
+ * @param title The card title.
1010
+ * @param images Optional. The array of images to include on the card.
1011
+ * @param buttons Optional. The array of buttons to include on the card. Each `string` in the array
1012
+ * is converted to an `imBack` button with a title and value set to the value of the string.
1013
+ * @param other Optional. Any additional properties to include on the card.
1014
+ *
1015
+ * @returns A bot message activity attached with a hero card.
1016
+ *
1017
+ * @example
1018
+ * ```javascript
1019
+ * const message = MessageBuilder.attachHeroCard(
1020
+ * 'sample title',
1021
+ * ['https://example.com/sample.jpg'],
1022
+ * ['action']
1023
+ * );
1024
+ * ```
1025
+ *
1026
+ * @beta
1027
+ */
1028
+ static attachHeroCard(title: string, images?: (CardImage | string)[], buttons?: (CardAction | string)[], other?: Partial<HeroCard>): Partial<Activity_2>;
1029
+ /**
1030
+ * Returns an attachment for a sign-in card.
1031
+ *
1032
+ * @param title The title for the card's sign-in button.
1033
+ * @param url The URL of the sign-in page to use.
1034
+ * @param text Optional. Additional text to include on the card.
1035
+ *
1036
+ * @returns A bot message activity attached with a sign-in card.
1037
+ *
1038
+ * @remarks
1039
+ * For channels that don't natively support sign-in cards, an alternative message is rendered.
1040
+ *
1041
+ * @beta
1042
+ */
1043
+ static attachSigninCard(title: string, url: string, text?: string): Partial<Activity_2>;
1044
+ /**
1045
+ * Build a bot message activity attached with an Office 365 connector card.
1046
+ *
1047
+ * @param card A description of the Office 365 connector card.
1048
+ * @returns A bot message activity attached with an Office 365 connector card.
1049
+ *
1050
+ * @beta
1051
+ */
1052
+ static attachO365ConnectorCard(card: O365ConnectorCard): Partial<Activity_2>;
1053
+ /**
1054
+ * Build a message activity attached with a receipt card.
1055
+ * @param card A description of the receipt card.
1056
+ * @returns A message activity attached with a receipt card.
1057
+ *
1058
+ * @beta
1059
+ */
1060
+ static AttachReceiptCard(card: ReceiptCard): Partial<Activity_2>;
1061
+ /**
1062
+ *
1063
+ * @param title The card title.
1064
+ * @param images Optional. The array of images to include on the card.
1065
+ * @param buttons Optional. The array of buttons to include on the card. Each `string` in the array
1066
+ * is converted to an `imBack` button with a title and value set to the value of the string.
1067
+ * @param other Optional. Any additional properties to include on the card.
1068
+ * @returns A message activity attached with a thumbnail card
1069
+ *
1070
+ * @beta
1071
+ */
1072
+ static attachThumbnailCard(title: string, images?: (CardImage | string)[], buttons?: (CardAction | string)[], other?: Partial<ThumbnailCard>): Partial<Activity_2>;
1073
+ /**
1074
+ * Add an attachement to a bot activity.
1075
+ * @param attachement The attachment object to attach.
1076
+ * @returns A message activity with an attachment.
1077
+ *
1078
+ * @beta
1079
+ */
1080
+ static attachContent(attachement: Attachment): Partial<Activity_2>;
1081
+ }
1196
1082
 
1197
- /**
1198
- * Interface for a storage provider that stores and retrieves notification target references.
1199
- *
1200
- * @beta
1201
- */
1202
- export declare interface NotificationTargetStorage {
1203
- /**
1204
- * Read one notification target by its key.
1205
- *
1206
- * @param key - the key of a notification target.
1207
- *
1208
- * @returns - the notification target. Or undefined if not found.
1209
- *
1210
- * @beta
1211
- */
1212
- read(key: string): Promise<{
1213
- [key: string]: unknown;
1214
- } | undefined>;
1215
- /**
1216
- * List all stored notification targets.
1217
- *
1218
- * @returns - an array of notification target. Or an empty array if nothing is stored.
1219
- *
1220
- * @beta
1221
- */
1222
- list(): Promise<{
1223
- [key: string]: unknown;
1224
- }[]>;
1225
- /**
1226
- * Write one notification target by its key.
1227
- *
1228
- * @param key - the key of a notification target.
1229
- * @param object - the notification target.
1230
- *
1231
- * @beta
1232
- */
1233
- write(key: string, object: {
1234
- [key: string]: unknown;
1235
- }): Promise<void>;
1236
- /**
1237
- * Delete one notificaton target by its key.
1238
- *
1239
- * @param key - the key of a notification target.
1240
- *
1241
- * @beta
1242
- */
1243
- delete(key: string): Promise<void>;
1244
- }
1083
+ /**
1084
+ * Microsoft Graph auth provider for Teams Framework
1085
+ *
1086
+ * @beta
1087
+ */
1088
+ export declare class MsGraphAuthProvider implements AuthenticationProvider {
1089
+ private teamsfx;
1090
+ private scopes;
1091
+ /**
1092
+ * Constructor of MsGraphAuthProvider.
1093
+ *
1094
+ * @param {TeamsFx} teamsfx - Used to provide configuration and auth.
1095
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
1096
+ *
1097
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1098
+ *
1099
+ * @returns An instance of MsGraphAuthProvider.
1100
+ *
1101
+ * @beta
1102
+ */
1103
+ constructor(teamsfx: TeamsFxConfiguration, scopes?: string | string[]);
1104
+ /**
1105
+ * Get access token for Microsoft Graph API requests.
1106
+ *
1107
+ * @throws {@link ErrorCode|InternalError} when get access token failed due to empty token or unknown other problems.
1108
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
1109
+ * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
1110
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth or AAD server.
1111
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1112
+ *
1113
+ * @returns Access token from the credential.
1114
+ *
1115
+ */
1116
+ getAccessToken(): Promise<string>;
1117
+ }
1245
1118
 
1246
- /**
1247
- * The target type where the notification will be sent to.
1248
- *
1249
- * @remarks
1250
- * - "Channel" means to a team channel. (By default, notification to a team will be sent to its "General" channel.)
1251
- * - "Group" means to a group chat.
1252
- * - "Person" means to a personal chat.
1253
- *
1254
- * @beta
1255
- */
1256
- export declare type NotificationTargetType = "Channel" | "Group" | "Person";
1119
+ /**
1120
+ * Provide utilities to send notification to varies targets (e.g., member, group, channel).
1121
+ *
1122
+ * @beta
1123
+ */
1124
+ export declare class NotificationBot {
1125
+ private readonly conversationReferenceStore;
1126
+ private readonly adapter;
1127
+ /**
1128
+ * constructor of the notification bot.
1129
+ *
1130
+ * @remarks
1131
+ * To ensure accuracy, it's recommended to initialize before handling any message.
1132
+ *
1133
+ * @param adapter - the bound `BotFrameworkAdapter`
1134
+ * @param options - initialize options
1135
+ *
1136
+ * @beta
1137
+ */
1138
+ constructor(adapter: BotFrameworkAdapter, options?: NotificationOptions_2);
1139
+ /**
1140
+ * Get all targets where the bot is installed.
1141
+ *
1142
+ * @remarks
1143
+ * The result is retrieving from the persisted storage.
1144
+ *
1145
+ * @returns - an array of {@link TeamsBotInstallation}.
1146
+ *
1147
+ * @beta
1148
+ */
1149
+ installations(): Promise<TeamsBotInstallation[]>;
1150
+ }
1257
1151
 
1258
- /**
1259
- * Represent on-behalf-of flow to get user identity, and it is designed to be used in server side.
1260
- *
1261
- * @example
1262
- * ```typescript
1263
- * const credential = new OnBehalfOfUserCredential(ssoToken);
1264
- * ```
1265
- *
1266
- * @remarks
1267
- * Can only be used in server side.
1268
- *
1269
- * @beta
1270
- */
1271
- export declare class OnBehalfOfUserCredential implements TokenCredential {
1272
- private msalClient;
1273
- private ssoToken;
1274
- /**
1275
- * Constructor of OnBehalfOfUserCredential
1276
- *
1277
- * @remarks
1278
- * Only works in in server side.
1279
- *
1280
- * @param {string} ssoToken - User token provided by Teams SSO feature.
1281
- * @param {AuthenticationConfiguration} config - The authentication configuration. Use environment variables if not provided.
1282
- *
1283
- * @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret, certificate content, authority host or tenant id is not found in config.
1284
- * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
1285
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1286
- *
1287
- * @beta
1288
- */
1289
- constructor(ssoToken: string, config: AuthenticationConfiguration);
1290
- /**
1291
- * Get access token from credential.
1292
- *
1293
- * @example
1294
- * ```typescript
1295
- * await credential.getToken([]) // Get SSO token using empty string array
1296
- * await credential.getToken("") // Get SSO token using empty string
1297
- * await credential.getToken([".default"]) // Get Graph access token with default scope using string array
1298
- * await credential.getToken(".default") // Get Graph access token with default scope using string
1299
- * await credential.getToken(["User.Read"]) // Get Graph access token for single scope using string array
1300
- * await credential.getToken("User.Read") // Get Graph access token for single scope using string
1301
- * await credential.getToken(["User.Read", "Application.Read.All"]) // Get Graph access token for multiple scopes using string array
1302
- * await credential.getToken("User.Read Application.Read.All") // Get Graph access token for multiple scopes using space-separated string
1303
- * await credential.getToken("https://graph.microsoft.com/User.Read") // Get Graph access token with full resource URI
1304
- * await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
1305
- * ```
1306
- *
1307
- * @param {string | string[]} scopes - The list of scopes for which the token will have access.
1308
- * @param {GetTokenOptions} options - The options used to configure any requests this TokenCredential implementation might make.
1309
- *
1310
- * @throws {@link ErrorCode|InternalError} when failed to acquire access token on behalf of user with unknown error.
1311
- * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
1312
- * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
1313
- * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
1314
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1315
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1316
- *
1317
- * @returns Access token with expected scopes.
1318
- *
1319
- * @remarks
1320
- * If scopes is empty string or array, it returns SSO token.
1321
- * If scopes is non-empty, it returns access token for target scope.
1322
- *
1323
- * @beta
1324
- */
1325
- getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
1326
- /**
1327
- * Get basic user info from SSO token.
1328
- *
1329
- * @example
1330
- * ```typescript
1331
- * const currentUser = getUserInfo();
1332
- * ```
1333
- *
1334
- * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
1335
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1336
- *
1337
- * @returns Basic user info with user displayName, objectId and preferredUserName.
1338
- *
1339
- * @beta
1340
- */
1341
- getUserInfo(): UserInfo;
1342
- private generateAuthServerError;
1343
- }
1152
+ /**
1153
+ * Options to initialize {@link NotificationBot}.
1154
+ *
1155
+ * @beta
1156
+ */
1157
+ declare interface NotificationOptions_2 {
1158
+ /**
1159
+ * An optional storage to persist bot notification connections.
1160
+ *
1161
+ * @remarks
1162
+ * If `storage` is not provided, a default local file storage will be used,
1163
+ * which stores notification connections into:
1164
+ * - ".notification.localstore.json" if running locally
1165
+ * - "${process.env.TEMP}/.notification.localstore.json" if `process.env.RUNNING_ON_AZURE` is set to "1"
1166
+ *
1167
+ * It's recommended to use your own shared storage for production environment.
1168
+ *
1169
+ * @beta
1170
+ */
1171
+ storage?: NotificationTargetStorage;
1172
+ }
1173
+ export { NotificationOptions_2 as NotificationOptions }
1344
1174
 
1345
- /**
1346
- * Send an adaptive card message to a notification target.
1347
- *
1348
- * @param target - the notification target.
1349
- * @param card - the adaptive card raw JSON.
1350
- * @returns A `Promise` representing the asynchronous operation.
1351
- *
1352
- * @beta
1353
- */
1354
- export declare function sendAdaptiveCard(target: NotificationTarget, card: unknown): Promise<void>;
1175
+ /**
1176
+ * Represent a notification target.
1177
+ *
1178
+ * @beta
1179
+ */
1180
+ export declare interface NotificationTarget {
1181
+ /**
1182
+ * The type of target, could be "Channel" or "Group" or "Person".
1183
+ *
1184
+ * @beta
1185
+ */
1186
+ readonly type?: NotificationTargetType;
1187
+ /**
1188
+ * Send a plain text message.
1189
+ *
1190
+ * @param text - the plain text message.
1191
+ *
1192
+ * @beta
1193
+ */
1194
+ sendMessage(text: string): Promise<void>;
1195
+ /**
1196
+ * Send an adaptive card message.
1197
+ *
1198
+ * @param card - the adaptive card raw JSON.
1199
+ *
1200
+ * @beta
1201
+ */
1202
+ sendAdaptiveCard(card: unknown): Promise<void>;
1203
+ }
1355
1204
 
1356
- /**
1357
- * Send a plain text message to a notification target.
1358
- *
1359
- * @param target - the notification target.
1360
- * @param text - the plain text message.
1361
- * @returns A `Promise` representing the asynchronous operation.
1362
- *
1363
- * @beta
1364
- */
1365
- export declare function sendMessage(target: NotificationTarget, text: string): Promise<void>;
1205
+ /**
1206
+ * Interface for a storage provider that stores and retrieves notification target references.
1207
+ *
1208
+ * @beta
1209
+ */
1210
+ export declare interface NotificationTargetStorage {
1211
+ /**
1212
+ * Read one notification target by its key.
1213
+ *
1214
+ * @param key - the key of a notification target.
1215
+ *
1216
+ * @returns - the notification target. Or undefined if not found.
1217
+ *
1218
+ * @beta
1219
+ */
1220
+ read(key: string): Promise<{
1221
+ [key: string]: unknown;
1222
+ } | undefined>;
1223
+ /**
1224
+ * List all stored notification targets.
1225
+ *
1226
+ * @returns - an array of notification target. Or an empty array if nothing is stored.
1227
+ *
1228
+ * @beta
1229
+ */
1230
+ list(): Promise<{
1231
+ [key: string]: unknown;
1232
+ }[]>;
1233
+ /**
1234
+ * Write one notification target by its key.
1235
+ *
1236
+ * @param key - the key of a notification target.
1237
+ * @param object - the notification target.
1238
+ *
1239
+ * @beta
1240
+ */
1241
+ write(key: string, object: {
1242
+ [key: string]: unknown;
1243
+ }): Promise<void>;
1244
+ /**
1245
+ * Delete one notificaton target by its key.
1246
+ *
1247
+ * @param key - the key of a notification target.
1248
+ *
1249
+ * @beta
1250
+ */
1251
+ delete(key: string): Promise<void>;
1252
+ }
1366
1253
 
1367
- /**
1368
- * Set custom log function. Use the function if it's set. Priority is lower than setLogger.
1369
- *
1370
- * @param {LogFunction} logFunction - custom log function. If it's undefined, custom log function will be cleared.
1371
- *
1372
- * @example
1373
- * ```typescript
1374
- * setLogFunction((level: LogLevel, message: string) => {
1375
- * if (level === LogLevel.Error) {
1376
- * console.log(message);
1377
- * }
1378
- * });
1379
- * ```
1380
- *
1381
- * @beta
1382
- */
1383
- export declare function setLogFunction(logFunction?: LogFunction): void;
1254
+ /**
1255
+ * The target type where the notification will be sent to.
1256
+ *
1257
+ * @remarks
1258
+ * - "Channel" means to a team channel. (By default, notification to a team will be sent to its "General" channel.)
1259
+ * - "Group" means to a group chat.
1260
+ * - "Person" means to a personal chat.
1261
+ *
1262
+ * @beta
1263
+ */
1264
+ export declare type NotificationTargetType = "Channel" | "Group" | "Person";
1384
1265
 
1385
- /**
1386
- * Set custom logger. Use the output functions if it's set. Priority is higher than setLogFunction.
1387
- *
1388
- * @param {Logger} logger - custom logger. If it's undefined, custom logger will be cleared.
1389
- *
1390
- * @example
1391
- * ```typescript
1392
- * setLogger({
1393
- * verbose: console.debug,
1394
- * info: console.info,
1395
- * warn: console.warn,
1396
- * error: console.error,
1397
- * });
1398
- * ```
1399
- *
1400
- * @beta
1401
- */
1402
- export declare function setLogger(logger?: Logger): void;
1266
+ /**
1267
+ * Represent on-behalf-of flow to get user identity, and it is designed to be used in server side.
1268
+ *
1269
+ * @example
1270
+ * ```typescript
1271
+ * const credential = new OnBehalfOfUserCredential(ssoToken);
1272
+ * ```
1273
+ *
1274
+ * @remarks
1275
+ * Can only be used in server side.
1276
+ *
1277
+ * @beta
1278
+ */
1279
+ export declare class OnBehalfOfUserCredential implements TokenCredential {
1280
+ private msalClient;
1281
+ private ssoToken;
1282
+ /**
1283
+ * Constructor of OnBehalfOfUserCredential
1284
+ *
1285
+ * @remarks
1286
+ * Only works in in server side.
1287
+ *
1288
+ * @param {string} ssoToken - User token provided by Teams SSO feature.
1289
+ * @param {AuthenticationConfiguration} config - The authentication configuration. Use environment variables if not provided.
1290
+ *
1291
+ * @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret, certificate content, authority host or tenant id is not found in config.
1292
+ * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
1293
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1294
+ *
1295
+ * @beta
1296
+ */
1297
+ constructor(ssoToken: string, config: AuthenticationConfiguration);
1298
+ /**
1299
+ * Get access token from credential.
1300
+ *
1301
+ * @example
1302
+ * ```typescript
1303
+ * await credential.getToken([]) // Get SSO token using empty string array
1304
+ * await credential.getToken("") // Get SSO token using empty string
1305
+ * await credential.getToken([".default"]) // Get Graph access token with default scope using string array
1306
+ * await credential.getToken(".default") // Get Graph access token with default scope using string
1307
+ * await credential.getToken(["User.Read"]) // Get Graph access token for single scope using string array
1308
+ * await credential.getToken("User.Read") // Get Graph access token for single scope using string
1309
+ * await credential.getToken(["User.Read", "Application.Read.All"]) // Get Graph access token for multiple scopes using string array
1310
+ * await credential.getToken("User.Read Application.Read.All") // Get Graph access token for multiple scopes using space-separated string
1311
+ * await credential.getToken("https://graph.microsoft.com/User.Read") // Get Graph access token with full resource URI
1312
+ * await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
1313
+ * ```
1314
+ *
1315
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
1316
+ * @param {GetTokenOptions} options - The options used to configure any requests this TokenCredential implementation might make.
1317
+ *
1318
+ * @throws {@link ErrorCode|InternalError} when failed to acquire access token on behalf of user with unknown error.
1319
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
1320
+ * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
1321
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
1322
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1323
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1324
+ *
1325
+ * @returns Access token with expected scopes.
1326
+ *
1327
+ * @remarks
1328
+ * If scopes is empty string or array, it returns SSO token.
1329
+ * If scopes is non-empty, it returns access token for target scope.
1330
+ *
1331
+ * @beta
1332
+ */
1333
+ getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
1334
+ /**
1335
+ * Get basic user info from SSO token.
1336
+ *
1337
+ * @example
1338
+ * ```typescript
1339
+ * const currentUser = getUserInfo();
1340
+ * ```
1341
+ *
1342
+ * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
1343
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1344
+ *
1345
+ * @returns Basic user info with user displayName, objectId and preferredUserName.
1346
+ *
1347
+ * @beta
1348
+ */
1349
+ getUserInfo(): UserInfo;
1350
+ private generateAuthServerError;
1351
+ }
1403
1352
 
1404
- /**
1405
- * Update log level helper.
1406
- *
1407
- * @param { LogLevel } level - log level in configuration
1408
- *
1409
- * @beta
1410
- */
1411
- export declare function setLogLevel(level: LogLevel): void;
1353
+ /**
1354
+ * Send an adaptive card message to a notification target.
1355
+ *
1356
+ * @param target - the notification target.
1357
+ * @param card - the adaptive card raw JSON.
1358
+ * @returns A `Promise` representing the asynchronous operation.
1359
+ *
1360
+ * @beta
1361
+ */
1362
+ export declare function sendAdaptiveCard(target: NotificationTarget, card: unknown): Promise<void>;
1412
1363
 
1413
- /**
1414
- * A {@link NotificationTarget} that represents a bot installation. Teams Bot could be installed into
1415
- * - Personal chat
1416
- * - Group chat
1417
- * - Team (by default the `General` channel)
1418
- *
1419
- * @remarks
1420
- * It's recommended to get bot installations from {@link ConversationBot.installations()}.
1421
- *
1422
- * @beta
1423
- */
1424
- export declare class TeamsBotInstallation implements NotificationTarget {
1425
- /**
1426
- * The bound `BotFrameworkAdapter`.
1427
- *
1428
- * @beta
1429
- */
1430
- readonly adapter: BotFrameworkAdapter;
1431
- /**
1432
- * The bound `ConversationReference`.
1433
- *
1434
- * @beta
1435
- */
1436
- readonly conversationReference: Partial<ConversationReference>;
1437
- /**
1438
- * Notification target type.
1439
- *
1440
- * @remarks
1441
- * - "Channel" means bot is installed into a team and notification will be sent to its "General" channel.
1442
- * - "Group" means bot is installed into a group chat.
1443
- * - "Person" means bot is installed into a personal scope and notification will be sent to personal chat.
1444
- *
1445
- * @beta
1446
- */
1447
- readonly type?: NotificationTargetType;
1448
- /**
1449
- * Constructor
1450
- *
1451
- * @remarks
1452
- * It's recommended to get bot installations from {@link ConversationBot.installations()}, instead of using this constructor.
1453
- *
1454
- * @param adapter - the bound `BotFrameworkAdapter`.
1455
- * @param conversationReference - the bound `ConversationReference`.
1456
- *
1457
- * @beta
1458
- */
1459
- constructor(adapter: BotFrameworkAdapter, conversationReference: Partial<ConversationReference>);
1460
- /**
1461
- * Send a plain text message.
1462
- *
1463
- * @param text - the plain text message.
1464
- * @returns A `Promise` representing the asynchronous operation.
1465
- *
1466
- * @beta
1467
- */
1468
- sendMessage(text: string): Promise<void>;
1469
- /**
1470
- * Send an adaptive card message.
1471
- *
1472
- * @param card - the adaptive card raw JSON.
1473
- * @returns A `Promise` representing the asynchronous operation.
1474
- *
1475
- * @beta
1476
- */
1477
- sendAdaptiveCard(card: unknown): Promise<void>;
1478
- /**
1479
- * Get channels from this bot installation.
1480
- *
1481
- * @returns an array of channels if bot is installed into a team, otherwise returns an empty array.
1482
- *
1483
- * @beta
1484
- */
1485
- channels(): Promise<Channel[]>;
1486
- /**
1487
- * Get members from this bot installation.
1488
- *
1489
- * @returns an array of members from where the bot is installed.
1490
- *
1491
- * @beta
1492
- */
1493
- members(): Promise<Member[]>;
1494
- }
1364
+ /**
1365
+ * Send a plain text message to a notification target.
1366
+ *
1367
+ * @param target - the notification target.
1368
+ * @param text - the plain text message.
1369
+ * @returns A `Promise` representing the asynchronous operation.
1370
+ *
1371
+ * @beta
1372
+ */
1373
+ export declare function sendMessage(target: NotificationTarget, text: string): Promise<void>;
1495
1374
 
1496
- /**
1497
- * Creates a new prompt that leverage Teams Single Sign On (SSO) support for bot to automatically sign in user and
1498
- * help receive oauth token, asks the user to consent if needed.
1499
- *
1500
- * @remarks
1501
- * The prompt will attempt to retrieve the users current token of the desired scopes and store it in
1502
- * the token store.
1503
- *
1504
- * User will be automatically signed in leveraging Teams support of Bot Single Sign On(SSO):
1505
- * https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots
1506
- *
1507
- * @example
1508
- * When used with your bots `DialogSet` you can simply add a new instance of the prompt as a named
1509
- * dialog using `DialogSet.add()`. You can then start the prompt from a waterfall step using either
1510
- * `DialogContext.beginDialog()` or `DialogContext.prompt()`. The user will be prompted to sign in as
1511
- * needed and their access token will be passed as an argument to the callers next waterfall step:
1512
- *
1513
- * ```JavaScript
1514
- * const { ConversationState, MemoryStorage } = require('botbuilder');
1515
- * const { DialogSet, WaterfallDialog } = require('botbuilder-dialogs');
1516
- * const { TeamsBotSsoPrompt } = require('@microsoft/teamsfx');
1517
- *
1518
- * const convoState = new ConversationState(new MemoryStorage());
1519
- * const dialogState = convoState.createProperty('dialogState');
1520
- * const dialogs = new DialogSet(dialogState);
1521
- *
1522
- * dialogs.add(new TeamsBotSsoPrompt('TeamsBotSsoPrompt', {
1523
- * scopes: ["User.Read"],
1524
- * }));
1525
- *
1526
- * dialogs.add(new WaterfallDialog('taskNeedingLogin', [
1527
- * async (step) => {
1528
- * return await step.beginDialog('TeamsBotSsoPrompt');
1529
- * },
1530
- * async (step) => {
1531
- * const token = step.result;
1532
- * if (token) {
1533
- *
1534
- * // ... continue with task needing access token ...
1535
- *
1536
- * } else {
1537
- * await step.context.sendActivity(`Sorry... We couldn't log you in. Try again later.`);
1538
- * return await step.endDialog();
1539
- * }
1540
- * }
1541
- * ]));
1542
- * ```
1543
- *
1544
- * @beta
1545
- */
1546
- export declare class TeamsBotSsoPrompt extends Dialog {
1547
- private teamsfx;
1548
- private settings;
1549
- /**
1550
- * Constructor of TeamsBotSsoPrompt.
1551
- *
1552
- * @param {TeamsFx} teamsfx - Used to provide configuration and auth
1553
- * @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
1554
- * @param settings Settings used to configure the prompt.
1555
- *
1556
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1557
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1558
- *
1559
- * @beta
1560
- */
1561
- constructor(teamsfx: TeamsFx, dialogId: string, settings: TeamsBotSsoPromptSettings);
1562
- /**
1563
- * Called when a prompt dialog is pushed onto the dialog stack and is being activated.
1564
- * @remarks
1565
- * If the task is successful, the result indicates whether the prompt is still
1566
- * active after the turn has been processed by the prompt.
1567
- *
1568
- * @param dc The DialogContext for the current turn of the conversation.
1569
- *
1570
- * @throws {@link ErrorCode|InvalidParameter} when timeout property in teams bot sso prompt settings is not number or is not positive.
1571
- * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
1572
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1573
- *
1574
- * @returns A `Promise` representing the asynchronous operation.
1575
- *
1576
- * @beta
1577
- */
1578
- beginDialog(dc: DialogContext): Promise<DialogTurnResult>;
1579
- /**
1580
- * Called when a prompt dialog is the active dialog and the user replied with a new activity.
1581
- *
1582
- * @remarks
1583
- * If the task is successful, the result indicates whether the dialog is still
1584
- * active after the turn has been processed by the dialog.
1585
- * The prompt generally continues to receive the user's replies until it accepts the
1586
- * user's reply as valid input for the prompt.
1587
- *
1588
- * @param dc The DialogContext for the current turn of the conversation.
1589
- *
1590
- * @returns A `Promise` representing the asynchronous operation.
1591
- *
1592
- * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
1593
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1594
- *
1595
- * @beta
1596
- */
1597
- continueDialog(dc: DialogContext): Promise<DialogTurnResult>;
1598
- private loadAndValidateConfig;
1599
- /**
1600
- * Ensure bot is running in MS Teams since TeamsBotSsoPrompt is only supported in MS Teams channel.
1601
- * @param dc dialog context
1602
- * @throws {@link ErrorCode|ChannelNotSupported} if bot channel is not MS Teams
1603
- * @internal
1604
- */
1605
- private ensureMsTeamsChannel;
1606
- /**
1607
- * Send OAuthCard that tells Teams to obtain an authentication token for the bot application.
1608
- * For details see https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots.
1609
- *
1610
- * @internal
1611
- */
1612
- private sendOAuthCardAsync;
1613
- /**
1614
- * Get sign in resource.
1615
- *
1616
- * @throws {@link ErrorCode|InvalidConfiguration} if client id, tenant id or initiate login endpoint is not found in config.
1617
- *
1618
- * @internal
1619
- */
1620
- private getSignInResource;
1621
- /**
1622
- * @internal
1623
- */
1624
- private recognizeToken;
1625
- /**
1626
- * @internal
1627
- */
1628
- private getTokenExchangeInvokeResponse;
1629
- /**
1630
- * @internal
1631
- */
1632
- private isTeamsVerificationInvoke;
1633
- /**
1634
- * @internal
1635
- */
1636
- private isTokenExchangeRequestInvoke;
1637
- /**
1638
- * @internal
1639
- */
1640
- private isTokenExchangeRequest;
1641
- }
1375
+ /**
1376
+ * Set custom log function. Use the function if it's set. Priority is lower than setLogger.
1377
+ *
1378
+ * @param {LogFunction} logFunction - custom log function. If it's undefined, custom log function will be cleared.
1379
+ *
1380
+ * @example
1381
+ * ```typescript
1382
+ * setLogFunction((level: LogLevel, message: string) => {
1383
+ * if (level === LogLevel.Error) {
1384
+ * console.log(message);
1385
+ * }
1386
+ * });
1387
+ * ```
1388
+ *
1389
+ * @beta
1390
+ */
1391
+ export declare function setLogFunction(logFunction?: LogFunction): void;
1642
1392
 
1643
- /**
1644
- * Settings used to configure an TeamsBotSsoPrompt instance.
1645
- *
1646
- * @beta
1647
- */
1648
- export declare interface TeamsBotSsoPromptSettings {
1649
- /**
1650
- * The array of strings that declare the desired permissions and the resources requested.
1651
- */
1652
- scopes: string[];
1653
- /**
1654
- * (Optional) number of milliseconds the prompt will wait for the user to authenticate.
1655
- * Defaults to a value `900,000` (15 minutes.)
1656
- */
1657
- timeout?: number;
1658
- /**
1659
- * (Optional) value indicating whether the TeamsBotSsoPrompt should end upon receiving an
1660
- * invalid message. Generally the TeamsBotSsoPrompt will end the auth flow when receives user
1661
- * message not related to the auth flow. Setting the flag to false ignores the user's message instead.
1662
- * Defaults to value `true`
1663
- */
1664
- endOnInvalidMessage?: boolean;
1665
- }
1393
+ /**
1394
+ * Set custom logger. Use the output functions if it's set. Priority is higher than setLogFunction.
1395
+ *
1396
+ * @param {Logger} logger - custom logger. If it's undefined, custom logger will be cleared.
1397
+ *
1398
+ * @example
1399
+ * ```typescript
1400
+ * setLogger({
1401
+ * verbose: console.debug,
1402
+ * info: console.info,
1403
+ * warn: console.warn,
1404
+ * error: console.error,
1405
+ * });
1406
+ * ```
1407
+ *
1408
+ * @beta
1409
+ */
1410
+ export declare function setLogger(logger?: Logger): void;
1666
1411
 
1667
- /**
1668
- * Token response provided by Teams Bot SSO prompt
1669
- *
1670
- * @beta
1671
- */
1672
- export declare interface TeamsBotSsoPromptTokenResponse extends TokenResponse {
1673
- /**
1674
- * SSO token for user
1675
- */
1676
- ssoToken: string;
1677
- /**
1678
- * Expire time of SSO token
1679
- */
1680
- ssoTokenExpiration: string;
1681
- }
1412
+ /**
1413
+ * Update log level helper.
1414
+ *
1415
+ * @param { LogLevel } level - log level in configuration
1416
+ *
1417
+ * @beta
1418
+ */
1419
+ export declare function setLogLevel(level: LogLevel): void;
1682
1420
 
1683
- /**
1684
- * A class providing credential and configuration.
1685
- * @beta
1686
- */
1687
- export declare class TeamsFx implements TeamsFxConfiguration {
1688
- private configuration;
1689
- private oboUserCredential?;
1690
- private appCredential?;
1691
- private identityType;
1692
- /**
1693
- * Constructor of TeamsFx
1694
- *
1695
- * @param {IdentityType} identityType - Choose user or app identity
1696
- * @param customConfig - key/value pairs of customized configuration that overrides default ones.
1697
- *
1698
- * @throws {@link ErrorCode|IdentityTypeNotSupported} when setting app identity in browser.
1699
- *
1700
- * @beta
1701
- */
1702
- constructor(identityType?: IdentityType, customConfig?: Record<string, string>);
1703
- /**
1704
- * Identity type set by user.
1705
- *
1706
- * @returns identity type.
1707
- * @beta
1708
- */
1709
- getIdentityType(): IdentityType;
1710
- /**
1711
- * Credential instance according to identity type choice.
1712
- *
1713
- * @remarks If user identity is chose, will return {@link TeamsUserCredential}
1714
- * in browser environment and {@link OnBehalfOfUserCredential} in NodeJS. If app
1715
- * identity is chose, will return {@link AppCredential}.
1716
- *
1717
- * @returns instance implements TokenCredential interface.
1718
- * @beta
1719
- */
1720
- getCredential(): TokenCredential;
1721
- /**
1722
- * Get user information.
1723
- * @returns UserInfo object.
1724
- * @beta
1725
- */
1726
- getUserInfo(): Promise<UserInfo>;
1727
- /**
1728
- * Popup login page to get user's access token with specific scopes.
1729
- *
1730
- * @remarks
1731
- * Only works in Teams client APP. User will be redirected to the authorization page to login and consent.
1732
- *
1733
- * @example
1734
- * ```typescript
1735
- * await teamsfx.login(["https://graph.microsoft.com/User.Read"]); // single scope using string array
1736
- * await teamsfx.login("https://graph.microsoft.com/User.Read"); // single scopes using string
1737
- * await teamsfx.login(["https://graph.microsoft.com/User.Read", "Calendars.Read"]); // multiple scopes using string array
1738
- * await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
1739
- * ```
1740
- * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
1741
- *
1742
- * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
1743
- * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
1744
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1745
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
1746
- *
1747
- * @beta
1748
- */
1749
- login(scopes: string | string[]): Promise<void>;
1750
- /**
1751
- * Set SSO token when using user identity in NodeJS.
1752
- * @param {string} ssoToken - used for on behalf of user flow.
1753
- * @returns self instance.
1754
- * @beta
1755
- */
1756
- setSsoToken(ssoToken: string): TeamsFx;
1757
- /**
1758
- * Usually used by service plugins to retrieve specific config
1759
- * @param {string} key - configuration key.
1760
- * @returns value in configuration.
1761
- * @beta
1762
- */
1763
- getConfig(key: string): string;
1764
- /**
1765
- * Check the value of specific key.
1766
- * @param {string} key - configuration key.
1767
- * @returns true if corresponding value is not empty string.
1768
- * @beta
1769
- */
1770
- hasConfig(key: string): boolean;
1771
- /**
1772
- * Get all configurations.
1773
- * @returns key value mappings.
1774
- * @beta
1775
- */
1776
- getConfigs(): Record<string, string>;
1777
- /**
1778
- * Load configuration from environment variables.
1779
- */
1780
- private loadFromEnv;
1781
- }
1421
+ /**
1422
+ * A {@link NotificationTarget} that represents a bot installation. Teams Bot could be installed into
1423
+ * - Personal chat
1424
+ * - Group chat
1425
+ * - Team (by default the `General` channel)
1426
+ *
1427
+ * @remarks
1428
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}.
1429
+ *
1430
+ * @beta
1431
+ */
1432
+ export declare class TeamsBotInstallation implements NotificationTarget {
1433
+ /**
1434
+ * The bound `BotFrameworkAdapter`.
1435
+ *
1436
+ * @beta
1437
+ */
1438
+ readonly adapter: BotFrameworkAdapter;
1439
+ /**
1440
+ * The bound `ConversationReference`.
1441
+ *
1442
+ * @beta
1443
+ */
1444
+ readonly conversationReference: Partial<ConversationReference>;
1445
+ /**
1446
+ * Notification target type.
1447
+ *
1448
+ * @remarks
1449
+ * - "Channel" means bot is installed into a team and notification will be sent to its "General" channel.
1450
+ * - "Group" means bot is installed into a group chat.
1451
+ * - "Person" means bot is installed into a personal scope and notification will be sent to personal chat.
1452
+ *
1453
+ * @beta
1454
+ */
1455
+ readonly type?: NotificationTargetType;
1456
+ /**
1457
+ * Constructor
1458
+ *
1459
+ * @remarks
1460
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}, instead of using this constructor.
1461
+ *
1462
+ * @param adapter - the bound `BotFrameworkAdapter`.
1463
+ * @param conversationReference - the bound `ConversationReference`.
1464
+ *
1465
+ * @beta
1466
+ */
1467
+ constructor(adapter: BotFrameworkAdapter, conversationReference: Partial<ConversationReference>);
1468
+ /**
1469
+ * Send a plain text message.
1470
+ *
1471
+ * @param text - the plain text message.
1472
+ * @returns A `Promise` representing the asynchronous operation.
1473
+ *
1474
+ * @beta
1475
+ */
1476
+ sendMessage(text: string): Promise<void>;
1477
+ /**
1478
+ * Send an adaptive card message.
1479
+ *
1480
+ * @param card - the adaptive card raw JSON.
1481
+ * @returns A `Promise` representing the asynchronous operation.
1482
+ *
1483
+ * @beta
1484
+ */
1485
+ sendAdaptiveCard(card: unknown): Promise<void>;
1486
+ /**
1487
+ * Get channels from this bot installation.
1488
+ *
1489
+ * @returns an array of channels if bot is installed into a team, otherwise returns an empty array.
1490
+ *
1491
+ * @beta
1492
+ */
1493
+ channels(): Promise<Channel[]>;
1494
+ /**
1495
+ * Get members from this bot installation.
1496
+ *
1497
+ * @returns an array of members from where the bot is installed.
1498
+ *
1499
+ * @beta
1500
+ */
1501
+ members(): Promise<Member[]>;
1502
+ }
1782
1503
 
1783
- /**
1784
- * Interface for a command handler that can process command to a TeamsFx bot and return a response.
1785
- *
1786
- * @beta
1787
- */
1788
- export declare interface TeamsFxBotCommandHandler {
1789
- /**
1790
- * The string or regular expression patterns that can trigger this handler.
1791
- */
1792
- triggerPatterns: TriggerPatterns;
1793
- /**
1794
- * Handles a bot command received activity.
1795
- *
1796
- * @param context The bot context.
1797
- * @param message The command message the user types from Teams.
1798
- * @returns A `Promise` representing an activity or text to send as the command response.
1799
- */
1800
- handleCommandReceived(context: TurnContext, message: CommandMessage): Promise<string | Partial<Activity>>;
1801
- }
1504
+ /**
1505
+ * Creates a new prompt that leverage Teams Single Sign On (SSO) support for bot to automatically sign in user and
1506
+ * help receive oauth token, asks the user to consent if needed.
1507
+ *
1508
+ * @remarks
1509
+ * The prompt will attempt to retrieve the users current token of the desired scopes and store it in
1510
+ * the token store.
1511
+ *
1512
+ * User will be automatically signed in leveraging Teams support of Bot Single Sign On(SSO):
1513
+ * https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots
1514
+ *
1515
+ * @example
1516
+ * When used with your bots `DialogSet` you can simply add a new instance of the prompt as a named
1517
+ * dialog using `DialogSet.add()`. You can then start the prompt from a waterfall step using either
1518
+ * `DialogContext.beginDialog()` or `DialogContext.prompt()`. The user will be prompted to sign in as
1519
+ * needed and their access token will be passed as an argument to the callers next waterfall step:
1520
+ *
1521
+ * ```JavaScript
1522
+ * const { ConversationState, MemoryStorage } = require('botbuilder');
1523
+ * const { DialogSet, WaterfallDialog } = require('botbuilder-dialogs');
1524
+ * const { TeamsBotSsoPrompt } = require('@microsoft/teamsfx');
1525
+ *
1526
+ * const convoState = new ConversationState(new MemoryStorage());
1527
+ * const dialogState = convoState.createProperty('dialogState');
1528
+ * const dialogs = new DialogSet(dialogState);
1529
+ *
1530
+ * dialogs.add(new TeamsBotSsoPrompt('TeamsBotSsoPrompt', {
1531
+ * scopes: ["User.Read"],
1532
+ * }));
1533
+ *
1534
+ * dialogs.add(new WaterfallDialog('taskNeedingLogin', [
1535
+ * async (step) => {
1536
+ * return await step.beginDialog('TeamsBotSsoPrompt');
1537
+ * },
1538
+ * async (step) => {
1539
+ * const token = step.result;
1540
+ * if (token) {
1541
+ *
1542
+ * // ... continue with task needing access token ...
1543
+ *
1544
+ * } else {
1545
+ * await step.context.sendActivity(`Sorry... We couldn't log you in. Try again later.`);
1546
+ * return await step.endDialog();
1547
+ * }
1548
+ * }
1549
+ * ]));
1550
+ * ```
1551
+ *
1552
+ * @beta
1553
+ */
1554
+ export declare class TeamsBotSsoPrompt extends Dialog {
1555
+ private teamsfx;
1556
+ private settings;
1557
+ /**
1558
+ * Constructor of TeamsBotSsoPrompt.
1559
+ *
1560
+ * @param {TeamsFx} teamsfx - Used to provide configuration and auth
1561
+ * @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
1562
+ * @param settings Settings used to configure the prompt.
1563
+ *
1564
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1565
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1566
+ *
1567
+ * @beta
1568
+ */
1569
+ constructor(teamsfx: TeamsFx, dialogId: string, settings: TeamsBotSsoPromptSettings);
1570
+ /**
1571
+ * Called when a prompt dialog is pushed onto the dialog stack and is being activated.
1572
+ * @remarks
1573
+ * If the task is successful, the result indicates whether the prompt is still
1574
+ * active after the turn has been processed by the prompt.
1575
+ *
1576
+ * @param dc The DialogContext for the current turn of the conversation.
1577
+ *
1578
+ * @throws {@link ErrorCode|InvalidParameter} when timeout property in teams bot sso prompt settings is not number or is not positive.
1579
+ * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
1580
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1581
+ *
1582
+ * @returns A `Promise` representing the asynchronous operation.
1583
+ *
1584
+ * @beta
1585
+ */
1586
+ beginDialog(dc: DialogContext): Promise<DialogTurnResult>;
1587
+ /**
1588
+ * Called when a prompt dialog is the active dialog and the user replied with a new activity.
1589
+ *
1590
+ * @remarks
1591
+ * If the task is successful, the result indicates whether the dialog is still
1592
+ * active after the turn has been processed by the dialog.
1593
+ * The prompt generally continues to receive the user's replies until it accepts the
1594
+ * user's reply as valid input for the prompt.
1595
+ *
1596
+ * @param dc The DialogContext for the current turn of the conversation.
1597
+ *
1598
+ * @returns A `Promise` representing the asynchronous operation.
1599
+ *
1600
+ * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
1601
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1602
+ *
1603
+ * @beta
1604
+ */
1605
+ continueDialog(dc: DialogContext): Promise<DialogTurnResult>;
1606
+ private loadAndValidateConfig;
1607
+ /**
1608
+ * Ensure bot is running in MS Teams since TeamsBotSsoPrompt is only supported in MS Teams channel.
1609
+ * @param dc dialog context
1610
+ * @throws {@link ErrorCode|ChannelNotSupported} if bot channel is not MS Teams
1611
+ * @internal
1612
+ */
1613
+ private ensureMsTeamsChannel;
1614
+ /**
1615
+ * Send OAuthCard that tells Teams to obtain an authentication token for the bot application.
1616
+ * For details see https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots.
1617
+ *
1618
+ * @internal
1619
+ */
1620
+ private sendOAuthCardAsync;
1621
+ /**
1622
+ * Get sign in resource.
1623
+ *
1624
+ * @throws {@link ErrorCode|InvalidConfiguration} if client id, tenant id or initiate login endpoint is not found in config.
1625
+ *
1626
+ * @internal
1627
+ */
1628
+ private getSignInResource;
1629
+ /**
1630
+ * @internal
1631
+ */
1632
+ private recognizeToken;
1633
+ /**
1634
+ * @internal
1635
+ */
1636
+ private getTokenExchangeInvokeResponse;
1637
+ /**
1638
+ * @internal
1639
+ */
1640
+ private isTeamsVerificationInvoke;
1641
+ /**
1642
+ * @internal
1643
+ */
1644
+ private isTokenExchangeRequestInvoke;
1645
+ /**
1646
+ * @internal
1647
+ */
1648
+ private isTokenExchangeRequest;
1649
+ }
1650
+
1651
+ /**
1652
+ * Settings used to configure an TeamsBotSsoPrompt instance.
1653
+ *
1654
+ * @beta
1655
+ */
1656
+ export declare interface TeamsBotSsoPromptSettings {
1657
+ /**
1658
+ * The array of strings that declare the desired permissions and the resources requested.
1659
+ */
1660
+ scopes: string[];
1661
+ /**
1662
+ * (Optional) number of milliseconds the prompt will wait for the user to authenticate.
1663
+ * Defaults to a value `900,000` (15 minutes.)
1664
+ */
1665
+ timeout?: number;
1666
+ /**
1667
+ * (Optional) value indicating whether the TeamsBotSsoPrompt should end upon receiving an
1668
+ * invalid message. Generally the TeamsBotSsoPrompt will end the auth flow when receives user
1669
+ * message not related to the auth flow. Setting the flag to false ignores the user's message instead.
1670
+ * Defaults to value `true`
1671
+ */
1672
+ endOnInvalidMessage?: boolean;
1673
+ }
1674
+
1675
+ /**
1676
+ * Token response provided by Teams Bot SSO prompt
1677
+ *
1678
+ * @beta
1679
+ */
1680
+ export declare interface TeamsBotSsoPromptTokenResponse extends TokenResponse {
1681
+ /**
1682
+ * SSO token for user
1683
+ */
1684
+ ssoToken: string;
1685
+ /**
1686
+ * Expire time of SSO token
1687
+ */
1688
+ ssoTokenExpiration: string;
1689
+ }
1690
+
1691
+ /**
1692
+ * A class providing credential and configuration.
1693
+ * @beta
1694
+ */
1695
+ export declare class TeamsFx implements TeamsFxConfiguration {
1696
+ private configuration;
1697
+ private oboUserCredential?;
1698
+ private appCredential?;
1699
+ private identityType;
1700
+ /**
1701
+ * Constructor of TeamsFx
1702
+ *
1703
+ * @param {IdentityType} identityType - Choose user or app identity
1704
+ * @param customConfig - key/value pairs of customized configuration that overrides default ones.
1705
+ *
1706
+ * @throws {@link ErrorCode|IdentityTypeNotSupported} when setting app identity in browser.
1707
+ *
1708
+ * @beta
1709
+ */
1710
+ constructor(identityType?: IdentityType, customConfig?: Record<string, string>);
1711
+ /**
1712
+ * Identity type set by user.
1713
+ *
1714
+ * @returns identity type.
1715
+ * @beta
1716
+ */
1717
+ getIdentityType(): IdentityType;
1718
+ /**
1719
+ * Credential instance according to identity type choice.
1720
+ *
1721
+ * @remarks If user identity is chose, will return {@link TeamsUserCredential}
1722
+ * in browser environment and {@link OnBehalfOfUserCredential} in NodeJS. If app
1723
+ * identity is chose, will return {@link AppCredential}.
1724
+ *
1725
+ * @returns instance implements TokenCredential interface.
1726
+ * @beta
1727
+ */
1728
+ getCredential(): TokenCredential;
1729
+ /**
1730
+ * Get user information.
1731
+ * @returns UserInfo object.
1732
+ * @beta
1733
+ */
1734
+ getUserInfo(): Promise<UserInfo>;
1735
+ /**
1736
+ * Popup login page to get user's access token with specific scopes.
1737
+ *
1738
+ * @remarks
1739
+ * Only works in Teams client APP. User will be redirected to the authorization page to login and consent.
1740
+ *
1741
+ * @example
1742
+ * ```typescript
1743
+ * await teamsfx.login(["https://graph.microsoft.com/User.Read"]); // single scope using string array
1744
+ * await teamsfx.login("https://graph.microsoft.com/User.Read"); // single scopes using string
1745
+ * await teamsfx.login(["https://graph.microsoft.com/User.Read", "Calendars.Read"]); // multiple scopes using string array
1746
+ * await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
1747
+ * ```
1748
+ * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
1749
+ *
1750
+ * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
1751
+ * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
1752
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1753
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
1754
+ *
1755
+ * @beta
1756
+ */
1757
+ login(scopes: string | string[]): Promise<void>;
1758
+ /**
1759
+ * Set SSO token when using user identity in NodeJS.
1760
+ * @param {string} ssoToken - used for on behalf of user flow.
1761
+ * @returns self instance.
1762
+ * @beta
1763
+ */
1764
+ setSsoToken(ssoToken: string): TeamsFx;
1765
+ /**
1766
+ * Usually used by service plugins to retrieve specific config
1767
+ * @param {string} key - configuration key.
1768
+ * @returns value in configuration.
1769
+ * @beta
1770
+ */
1771
+ getConfig(key: string): string;
1772
+ /**
1773
+ * Check the value of specific key.
1774
+ * @param {string} key - configuration key.
1775
+ * @returns true if corresponding value is not empty string.
1776
+ * @beta
1777
+ */
1778
+ hasConfig(key: string): boolean;
1779
+ /**
1780
+ * Get all configurations.
1781
+ * @returns key value mappings.
1782
+ * @beta
1783
+ */
1784
+ getConfigs(): Record<string, string>;
1785
+ /**
1786
+ * Load configuration from environment variables.
1787
+ */
1788
+ private loadFromEnv;
1789
+ }
1802
1790
 
1803
- /**
1804
- * TeamsFx interface that provides credential and configuration.
1805
- * @beta
1806
- */
1807
- declare interface TeamsFxConfiguration {
1808
- /**
1809
- * Identity type set by user.
1810
- *
1811
- * @returns identity type.
1812
- * @beta
1813
- */
1814
- getIdentityType(): IdentityType;
1815
- /**
1816
- * Credential instance according to identity type choice.
1817
- *
1818
- * @remarks If user identity is chose, will return {@link TeamsUserCredential}
1819
- * in browser environment and {@link OnBehalfOfUserCredential} in NodeJS. If app
1820
- * identity is chose, will return {@link AppCredential}.
1821
- *
1822
- * @returns instance implements TokenCredential interface.
1823
- * @beta
1824
- */
1825
- getCredential(): TokenCredential;
1826
- /**
1827
- * Get user information.
1828
- * @returns UserInfo object.
1829
- * @beta
1830
- */
1831
- getUserInfo(): Promise<UserInfo>;
1832
- /**
1833
- * Popup login page to get user's access token with specific scopes.
1834
- *
1835
- * @remarks
1836
- * Only works in Teams client APP. User will be redirected to the authorization page to login and consent.
1837
- *
1838
- * @example
1839
- * ```typescript
1840
- * await teamsfx.login(["https://graph.microsoft.com/User.Read"]); // single scope using string array
1841
- * await teamsfx.login("https://graph.microsoft.com/User.Read"); // single scopes using string
1842
- * await teamsfx.login(["https://graph.microsoft.com/User.Read", "Calendars.Read"]); // multiple scopes using string array
1843
- * await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
1844
- * ```
1845
- * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
1846
- *
1847
- * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
1848
- * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
1849
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1850
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
1851
- *
1852
- * @beta
1853
- */
1854
- login(scopes: string | string[]): Promise<void>;
1855
- /**
1856
- * Set SSO token when using user identity in NodeJS.
1857
- * @param {string} ssoToken - used for on behalf of user flow.
1858
- * @returns self instance.
1859
- * @beta
1860
- */
1861
- setSsoToken(ssoToken: string): TeamsFxConfiguration;
1862
- /**
1863
- * Usually used by service plugins to retrieve specific config
1864
- * @param {string} key - configuration key.
1865
- * @returns value in configuration.
1866
- * @beta
1867
- */
1868
- getConfig(key: string): string;
1869
- /**
1870
- * Check the value of specific key.
1871
- * @param {string} key - configuration key.
1872
- * @returns true if corresponding value is not empty string.
1873
- * @beta
1874
- */
1875
- hasConfig(key: string): boolean;
1876
- /**
1877
- * Get all configurations.
1878
- * @returns key value mappings.
1879
- * @beta
1880
- */
1881
- getConfigs(): Record<string, string>;
1882
- }
1791
+ /**
1792
+ * Interface for a command handler that can process command to a TeamsFx bot and return a response.
1793
+ *
1794
+ * @beta
1795
+ */
1796
+ export declare interface TeamsFxBotCommandHandler {
1797
+ /**
1798
+ * The string or regular expression patterns that can trigger this handler.
1799
+ */
1800
+ triggerPatterns: TriggerPatterns;
1801
+ /**
1802
+ * Handles a bot command received activity.
1803
+ *
1804
+ * @param context The bot context.
1805
+ * @param message The command message the user types from Teams.
1806
+ * @returns A `Promise` representing an activity or text to send as the command response.
1807
+ */
1808
+ handleCommandReceived(context: TurnContext, message: CommandMessage): Promise<string | Partial<Activity>>;
1809
+ }
1883
1810
 
1884
- /**
1885
- * Represent Teams current user's identity, and it is used within Teams client applications.
1886
- *
1887
- * @remarks
1888
- * Can only be used within Teams.
1889
- *
1890
- * @beta
1891
- */
1892
- export declare class TeamsUserCredential implements TokenCredential {
1893
- /**
1894
- * Constructor of TeamsUserCredential.
1895
- * @remarks
1896
- * Can only be used within Teams.
1897
- * @beta
1898
- */
1899
- constructor(authConfig: AuthenticationConfiguration);
1900
- /**
1901
- * Popup login page to get user's access token with specific scopes.
1902
- * @remarks
1903
- * Can only be used within Teams.
1904
- * @beta
1905
- */
1906
- login(scopes: string | string[]): Promise<void>;
1907
- /**
1908
- * Get access token from credential.
1909
- * @remarks
1910
- * Can only be used within Teams.
1911
- * @beta
1912
- */
1913
- getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
1914
- /**
1915
- * Get basic user info from SSO token
1916
- * @remarks
1917
- * Can only be used within Teams.
1918
- * @beta
1919
- */
1920
- getUserInfo(): Promise<UserInfo>;
1921
- }
1811
+ /**
1812
+ * TeamsFx interface that provides credential and configuration.
1813
+ * @beta
1814
+ */
1815
+ declare interface TeamsFxConfiguration {
1816
+ /**
1817
+ * Identity type set by user.
1818
+ *
1819
+ * @returns identity type.
1820
+ * @beta
1821
+ */
1822
+ getIdentityType(): IdentityType;
1823
+ /**
1824
+ * Credential instance according to identity type choice.
1825
+ *
1826
+ * @remarks If user identity is chose, will return {@link TeamsUserCredential}
1827
+ * in browser environment and {@link OnBehalfOfUserCredential} in NodeJS. If app
1828
+ * identity is chose, will return {@link AppCredential}.
1829
+ *
1830
+ * @returns instance implements TokenCredential interface.
1831
+ * @beta
1832
+ */
1833
+ getCredential(): TokenCredential;
1834
+ /**
1835
+ * Get user information.
1836
+ * @returns UserInfo object.
1837
+ * @beta
1838
+ */
1839
+ getUserInfo(): Promise<UserInfo>;
1840
+ /**
1841
+ * Popup login page to get user's access token with specific scopes.
1842
+ *
1843
+ * @remarks
1844
+ * Only works in Teams client APP. User will be redirected to the authorization page to login and consent.
1845
+ *
1846
+ * @example
1847
+ * ```typescript
1848
+ * await teamsfx.login(["https://graph.microsoft.com/User.Read"]); // single scope using string array
1849
+ * await teamsfx.login("https://graph.microsoft.com/User.Read"); // single scopes using string
1850
+ * await teamsfx.login(["https://graph.microsoft.com/User.Read", "Calendars.Read"]); // multiple scopes using string array
1851
+ * await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
1852
+ * ```
1853
+ * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
1854
+ *
1855
+ * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
1856
+ * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
1857
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1858
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
1859
+ *
1860
+ * @beta
1861
+ */
1862
+ login(scopes: string | string[]): Promise<void>;
1863
+ /**
1864
+ * Set SSO token when using user identity in NodeJS.
1865
+ * @param {string} ssoToken - used for on behalf of user flow.
1866
+ * @returns self instance.
1867
+ * @beta
1868
+ */
1869
+ setSsoToken(ssoToken: string): TeamsFxConfiguration;
1870
+ /**
1871
+ * Usually used by service plugins to retrieve specific config
1872
+ * @param {string} key - configuration key.
1873
+ * @returns value in configuration.
1874
+ * @beta
1875
+ */
1876
+ getConfig(key: string): string;
1877
+ /**
1878
+ * Check the value of specific key.
1879
+ * @param {string} key - configuration key.
1880
+ * @returns true if corresponding value is not empty string.
1881
+ * @beta
1882
+ */
1883
+ hasConfig(key: string): boolean;
1884
+ /**
1885
+ * Get all configurations.
1886
+ * @returns key value mappings.
1887
+ * @beta
1888
+ */
1889
+ getConfigs(): Record<string, string>;
1890
+ }
1891
+
1892
+ /**
1893
+ * Represent Teams current user's identity, and it is used within Teams client applications.
1894
+ *
1895
+ * @remarks
1896
+ * Can only be used within Teams.
1897
+ *
1898
+ * @beta
1899
+ */
1900
+ export declare class TeamsUserCredential implements TokenCredential {
1901
+ /**
1902
+ * Constructor of TeamsUserCredential.
1903
+ * @remarks
1904
+ * Can only be used within Teams.
1905
+ * @beta
1906
+ */
1907
+ constructor(authConfig: AuthenticationConfiguration);
1908
+ /**
1909
+ * Popup login page to get user's access token with specific scopes.
1910
+ * @remarks
1911
+ * Can only be used within Teams.
1912
+ * @beta
1913
+ */
1914
+ login(scopes: string | string[]): Promise<void>;
1915
+ /**
1916
+ * Get access token from credential.
1917
+ * @remarks
1918
+ * Can only be used within Teams.
1919
+ * @beta
1920
+ */
1921
+ getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
1922
+ /**
1923
+ * Get basic user info from SSO token
1924
+ * @remarks
1925
+ * Can only be used within Teams.
1926
+ * @beta
1927
+ */
1928
+ getUserInfo(): Promise<UserInfo>;
1929
+ }
1922
1930
 
1923
- /**
1924
- * The trigger pattern used to trigger a {@link TeamsFxBotCommandHandler} instance.
1925
- */
1926
- export declare type TriggerPatterns = string | RegExp | (string | RegExp)[];
1931
+ /**
1932
+ * The trigger pattern used to trigger a {@link TeamsFxBotCommandHandler} instance.
1933
+ */
1934
+ export declare type TriggerPatterns = string | RegExp | (string | RegExp)[];
1927
1935
 
1928
- /**
1929
- * UserInfo with user displayName, objectId and preferredUserName.
1930
- *
1931
- * @beta
1932
- */
1933
- export declare interface UserInfo {
1934
- /**
1935
- * User Display Name.
1936
- *
1937
- * @readonly
1938
- */
1939
- displayName: string;
1940
- /**
1941
- * User unique reference within the Azure Active Directory domain.
1942
- *
1943
- * @readonly
1944
- */
1945
- objectId: string;
1946
- /**
1947
- * Usually be the email address.
1948
- *
1949
- * @readonly
1950
- */
1951
- preferredUserName: string;
1952
- }
1936
+ /**
1937
+ * UserInfo with user displayName, objectId and preferredUserName.
1938
+ *
1939
+ * @beta
1940
+ */
1941
+ export declare interface UserInfo {
1942
+ /**
1943
+ * User Display Name.
1944
+ *
1945
+ * @readonly
1946
+ */
1947
+ displayName: string;
1948
+ /**
1949
+ * User unique reference within the Azure Active Directory domain.
1950
+ *
1951
+ * @readonly
1952
+ */
1953
+ objectId: string;
1954
+ /**
1955
+ * Usually be the email address.
1956
+ *
1957
+ * @readonly
1958
+ */
1959
+ preferredUserName: string;
1960
+ }
1953
1961
 
1954
- export { }
1962
+ export { }