Updates from: 10/04/2022 01:30:39
Service Microsoft Docs article Related commit history on GitHub Change details
platform Conversation Messages https://github.com/MicrosoftDocs/msteams-docs/commits/main/msteams-platform/bots/how-to/conversations/conversation-messages.md
Title: Messages in bot conversations
-description: Learn how to send recieve a message, suggested actions, notification, attachments, images, Adaptive Cards, status error code responses for Throttle.
+description: Learn how to send receive a message, suggested actions, notification, attachments, images, Adaptive Card and status error code responses.
ms.localizationpriority: medium
Messages received from or sent to your bot can include different types of messag
## Notifications to your message
-You can also add notifications to your message using the `Notification.Alert` property. Notifications alert users about new tasks, mentions, and comments. These alerts are related to what users are working on or what they must look at by inserting a notice into their activity feed. For notifications to trigger from your bot message, set the `TeamsChannelData` objects `Notification.Alert` property to *true*. Whether or not a notification is raised depends on the individual user's Teams settings and you can't override these settings. The notification type is either a banner, or both a banner and an email.
+You can also add notifications to your message using the `Notification.Alert` property. Notifications alert users about new tasks, mentions, and comments. These alerts are related to what users are working on or what they must look at by inserting a notice into their activity feed. For notifications to trigger from your bot message, set the `TeamsChannelData` objects `Notification.Alert` property to *true*. Whether or not a notification is raised depends on the individual user's Teams settings and you can't override these settings. The notification type is either a banner or both a banner and an email.
> [!NOTE] > The **Summary** field displays any text from the user as a notification message in the feed.
Form completion message appears in Adaptive Cards while sending a response to th
For more information on cards and cards in bots, see [cards documentation](~/task-modules-and-cards/what-are-cards.md).
-## Status code responses
-
-Following are the status codes and their error code and message values:
-
-| Status code | Error code and message values | Description |
-|-|--|--|
-| 403 | **Code**: `ConversationBlockedByUser` <br/> **Message**: User blocked the conversation with the bot. | User blocked the bot in 1:1 chat or a channel through moderation settings. |
-| 403 | **Code**: `BotNotInConversationRoster` <br/> **Message**: The bot isn't part of the conversation roster. | The bot isn't part of the conversation. |
-| 403 | **Code**: `BotDisabledByAdmin` <br/> **Message**: The tenant admin disabled this bot. | Tenant blocked the bot. |
-| 401 | **Code**: `BotNotRegistered` <br/> **Message**: No registration found for this bot. | The registration for this bot wasn't found. |
-| 412 | **Code**: `PreconditionFailed` <br/> **Message**: Precondition failed, please try again. | A precondition failed on one of our dependencies due to multiple concurrent operations on the same conversation. |
-| 404 | **Code**: `ConversationNotFound` <br/> **Message**: Conversation not found. | The conversation wasn't found. |
-| 413 | **Code**: `MessageSizeTooBig` <br/> **Message**: Message size too large. | The size on the incoming request was too large. |
-| 429 | **Code**: `Throttled` <br/> **Message**: Too many requests. Also returns when to retry after. | Too many requests were sent by the bot. For more information, see [rate limit](~/bots/how-to/rate-limit.md). |
+## Status codes from bot conversational APIs
+
+Ensure to handle these errors appropriately in your Teams app. The following table lists the error codes and the descriptions under which the errors are generated:
+
+| Status code | Error code and message values | Description | Retry request | Developer action |
+|-|--|--|-|-|
+| 400 | **Code**: `Bad Argument` <br/> **Message**: *scenario specific | Invalid request payload provided by the bot. See error message for specific details. | No | Re-evaluate request payload for errors. Check returned error message for details. |
+| 401 | **Code**: `BotNotRegistered` <br/> **Message**: No registration found for this bot. | The registration for this bot wasn't found. | No | Verify the bot ID and password. Ensure that the bot ID (AAD ID) is registered in the Teams Developer Portal or via Azure bot channel registration in Azure with 'Teams' channel enabled.|
+| 403 | **Code**: `BotDisabledByAdmin` <br/> **Message**: The tenant admin disabled this bot | Tenant admin has blocked interactions between user and the bot app. Tenant admin needs to allow the app for the user inside of app policies. For more information, see [app policies](/microsoftteams/app-policies). | No | Stop posting to conversation until interaction with bot is explicitly initiated by a user in the conversation indicating that the bot is no longer blocked. |
+| 403 | **Code**: `BotNotInConversationRoster` <br/> **Message**: The bot isn't part of the conversation roster. | The bot isn't part of the conversation. App needs to be reinstalled in conversation. | No | Before attempting to send additional conversation requests, wait for an [`installationUpdate`](~/bots/how-to/conversations/subscribe-to-conversation-events.md#install-update-event) event, which indicates that the bot has been re-added.|
+| 403 | **Code**: `ConversationBlockedByUser` <br/> **Message**: User blocked the conversation with the bot. | User has blocked the bot in personal chat or a channel through moderation settings. | No | Delete the conversation from cache. Stop attempting to post to conversations until interaction with bot is explicitly initiated by a user in the conversation, indicating that the bot is no longer blocked. |
+| 403 | **Code**: `NotEnoughPermissions` <br/> **Message**: *scenario specific | Bot doesn't have required permissions to perform the requested action. | No | Determine the required action from the error message. |
+| 404 | **Code**: `ActivityNotFoundInConversation` <br/> **Message**: Conversation not found. | The message ID provided couldn't be found in the conversation. Message doesn't exist or it has been deleted. | No | Check if message ID sent is an expected value. Remove the ID if it was cached. |
+| 404 | **Code**: `ConversationNotFound` <br/> **Message**: Conversation not found. | Conversation wasn't found as it doesn't exist or has been deleted. | No | Check if conversation ID sent is an expected value. Remove the ID if it was cached. |
+| 412 | **Code**: `PreconditionFailed` <br/> **Message**: Precondition failed, please try again. | A precondition failed on one of our dependencies due to multiple concurrent operations on the same conversation. | Yes | Retry with exponential backoff. |
+| 413 | **Code**: `MessageSizeTooBig` <br/> **Message**: Message size too large. | The size of the incoming request was too large. For more information, see [format your bot messages](/microsoftteams/platform/bots/how-to/format-your-bot-messages). | No | Reduce the payload size. |
+| 429 | **Code**: `Throttled` <br/> **Message**: Too many requests. Also returns when to retry after. | Too many requests were sent by the bot. For more information, see [rate limit](/microsoftteams/platform/bots/how-to/rate-limit). | Yes | Retry using `Retry-After` header to determine backoff time. |
+| 500 | **Code**: `ServiceError` <br/> **Message**: *various | Internal server error. | No | Report the issue in [developer community](~/feedback.md#developer-community-help). |
+| 502 | **Code**: `ServiceError` <br/> **Message**: *various | Service dependency issue. | Yes | Retry with exponential backoff. If the issue persists, report the issue in [developer community](~/feedback.md#developer-community-help). |
+| 503 | | Service is unavailable. | Yes | Retry with exponential backoff. If the issue persists, report the issue in [developer community](~/feedback.md#developer-community-help). |
+| 504 | | Gateway Timeout. | Yes | Retry with exponential backoff. If the issue persists, report the issue in [developer community](~/feedback.md#developer-community-help). |
+
+### Status codes retry guidance
+
+The general retry guidance for each status code is listed in the following table. Bot should avoid retrying on status codes that are not specified in the following table:
+
+|Status code | Retry strategy |
+|-|--|
+| 412 | Retry using exponential backoff. |
+| 429 | Retry using `Retry-After` header to determine wait time in seconds and in between requests, if available . Otherwise, retry using exponential backoff with thread ID, if possible. |
+| 502 | Retry using exponential backoff. |
+| 503 | Retry using exponential backoff. |
+| 504 | Retry using exponential backoff. |
## Code sample
platform Publish https://github.com/MicrosoftDocs/msteams-docs/commits/main/msteams-platform/concepts/deploy-and-publish/appsource/publish.md
Title: Overview - Publish your app to the Microsoft Teams store
-description: Underdtand the process fo publishing your app to Microsoft Teams store, what to expect after you submit, tips for rapid approval to publish ypu app and app linked to a SaaS offer.
+description: Understand the process for publishing your app to Microsoft Teams store, what to expect after you submit, tips for rapid approval to publish your app and app linked to a SaaS offer.
platform Create Channel Group Tab https://github.com/MicrosoftDocs/msteams-docs/commits/main/msteams-platform/tabs/how-to/create-channel-group-tab.md
gulp ngrok-serve
### Upload your application to Teams 1. Go to Teams and select **Apps**&nbsp;:::image type="content" source="~/assets/images/tab-images/store.png" alt-text="Teams Store":::.
-1. Select **Manage your apps** and **Upload a custom app**.
+1. Select **Manage your apps** > **Upload an app** > **Upload a custom app**.
1. Go to your project directory, browse to the **./package** folder, select the app package zip folder, and choose **Open**. :::image type="content" source="~/assets/images/tab-images/channeltabadded.png" alt-text="Uploaded channel tab":::
Ensure that you keep the command prompt with ngrok running and make a note of th
1. In **App URLs**, update the Privacy policy to `https://<yourngrokurl>/privacy` and Terms of use to `https://<yourngrokurl>/tou` and save.
-1. In **App features**, select Group and channel app. Update the **Configuration URL** with `https://<yourngrokurl>/tab` and select your tab **Scope**.
+1. In **App features**, select **Group and channel app**. Update the **Configuration URL** with `https://<yourngrokurl>/tab` and select your tab **Scope**.
1. Select **Save**.
Ensure that you keep the command prompt with ngrok running and make a note of th
1. In **App URLs**, update the Privacy policy to `https://<yourngrokurl>/privacy` and Terms of use to `https://<yourngrokurl>/tou` and save.
-1. In **App features**, select Group and channel app. Update the **Configuration URL** with `https://<yourngrokurl>/tab` and select your tab **Scope**.
+1. In **App features**, select **Group and channel app**. Update the **Configuration URL** with `https://<yourngrokurl>/tab` and select your tab **Scope**.
1. Select **Save**.
platform Create Personal Tab https://github.com/MicrosoftDocs/msteams-docs/commits/main/msteams-platform/tabs/how-to/create-personal-tab.md
gulp ngrok-serve
### Upload your application to Teams 1. Go to Teams and select **Apps**&nbsp;:::image type="content" source="~/assets/images/tab-images/store.png" alt-text="Teams Store":::.
-1. Select **Manage your apps** and **Upload a custom app**.
+1. Select **Manage your apps** > **Upload an app** > **Upload a custom app**.
1. Go to your project directory, browse to the **./package** folder, select the zip folder, and choose **Open**. :::image type="content" source="~/assets/images/tab-images/addingpersonaltab.png" alt-text="Adding your personal tab":::
ngrok http 3978 --host-header=localhost
1. In **Developer Information**, add the required details and in **Website (must be a valid HTTPS URL)** give your ngrok HTTPS URL.
-1. In **App URLs**, update the Privacy policy to `https://<yourngrokurl>/privacy` and Terms of use to `https://<yourngrokurl>/tou` and save.
+1. In **App URLs**, update the Privacy policy to `https://<yourngrokurl>/privacy` and Terms of use to `https://<yourngrokurl>/tou` and select **Save**.
-1. In **App features**, select **Personal app** > **Create your first personal app tab** and enter the Name and update the **Content URL** with `https://<yourngrokurl>/personalTab`. Leave the Website URL field blank and select **Context** as personalTab from the dropdown list and **Add**.
+1. In **App features**, select **Personal app** > **Create your first personal app tab** and enter the Name and update the **Content URL** with `https://<yourngrokurl>/personalTab`. Leave the Website URL field blank and select **Context** as personalTab from the dropdown list and select **Confirm**.
1. Select **Save**.
ngrok http 3978 --host-header=localhost
1. Add the Short and Long description for your app in **Descriptions**.
-1. In **Developer Information**, add the required details and in **Website (must be a valid HTTPS URL)** give your ngrok HTTPS URL.
+1. In **Developer information**, add the required details and in **Website (must be a valid HTTPS URL)** give your ngrok HTTPS URL.
-1. In **App URLs**, update the Privacy policy to `https://<yourngrokurl>/privacy` and Terms of use to `https://<yourngrokurl>/tou` and save.
+1. In **App URLs**, update the Privacy policy to `https://<yourngrokurl>/privacy` and Terms of use to `https://<yourngrokurl>/tou` and select **Save**.
-1. In **App features**, select **Personal app** > **Create your first personal app tab** and enter the Name and update the **Content URL** with `https://<yourngrokurl>/personalTab`. Leave the Website URL field blank and select **Context** as personalTab from the dropdown list and **Add**.
+1. In **App features**, select **Personal app** > **Create your first personal app tab** and enter the Name and update the **Content URL** with `https://<yourngrokurl>/personalTab`. Leave the Website URL field blank and select **Context** as personalTab from the dropdown list and select **Confirm**.
1. Select **Save**.
platform Teamsfx SDK https://github.com/MicrosoftDocs/msteams-docs/commits/main/msteams-platform/toolkit/TeamsFx-SDK.md
Last updated 11/29/2021
# TeamsFx SDK
-TeamsFx helps to reduce your tasks by using Microsoft Teams Single-Sign-On (Teams SSO) and accessing cloud resources down to single line statements with zero configuration. You can use TeamsFx SDK in browser and Node.js environment. TeamsFx core functionalities can be accessed in client as well as server environment. You can write user authentication code in a simplified way for:
+TeamsFx helps to reduce your tasks by using Microsoft Teams Single-Sign-On (Teams SSO) and accessing cloud resources down to single line statements with zero configuration. You can use TeamsFx SDK in browser and Node.js environment. TeamsFx core functionalities can be accessed in client and server environment. You can write user authentication code in a simplified way for:
* Teams tab * Teams bot
You can learn more about user identity and application identity in the following
### Credential
-To initialize TeamsFx, you must choose the required identity type. Post specifying the identity type SDK uses different type of credential class. These help represent the identity and get access token by corresponding auth flow. Credential classes implement `TokenCredential` interface that is broadly used in Azure library APIs designed to provide access tokens for specific scopes. Other APIs rely on credential call `TeamsFx:getCredential()` to get an instance of `TokenCredential`. For more information on credential and auth flow related classes, see [credential folder](https://github.com/OfficeDev/TeamsFx/tree/main/packages/sdk/src/credential).
+To initialize TeamsFx, you must choose the required identity type. Post specifying the identity type SDK uses different type of credential class. These represent the identity and get access token by corresponding auth flow. Credential classes implement `TokenCredential` interface that is broadly used in Azure library APIs designed to provide access tokens for specific scopes. Other APIs rely on credential call `TeamsFx:getCredential()` to get an instance of `TokenCredential`. For more information on credential and auth flow related classes, see [credential folder](https://github.com/OfficeDev/TeamsFx/tree/main/packages/sdk/src/credential).
There are three credential classes to simplify authentication. Here's the corresponding scenarios for each credential class target.
TeamsFx SDK provides several functions to ease the configuration for third-party
* Microsoft Graph Service:`createMicrosoftGraphClient` and `MsGraphAuthProvider` help to create authenticated Graph instance. * SQL:`getTediousConnectionConfig` returns a tedious connection config.
-Required configuration:
+ Required configuration:
-* If you want to use user identity then `sqlServerEndpoint`, `sqlUsername` and `sqlPassword` are required.
-* If you want to use MSI identity then `sqlServerEndpoint`and `sqlIdentityId` are required.
+ * If you want to use user identity, then `sqlServerEndpoint`, `sqlUsername` and `sqlPassword` are required.
+ * If you want to use MSI identity, then `sqlServerEndpoint`and `sqlIdentityId` are required.
### Override configuration
If you've created Azure function or bot project using Visual Studio Code Toolkit
* clientSecret (M365_CLIENT_SECRET) * applicationIdUri (M365_APPLICATION_ID_URI) * apiEndpoint (API_ENDPOINT)
-* sqlServerEndpoint (SQL_ENDPOINT) // only used when there's a sql instance
-* sqlUsername (SQL_USER_NAME) // only used when there's a sql instance
-* sqlPassword (SQL_PASSWORD) // only used when there's a sql instance
-* sqlDatabaseName (SQL_DATABASE_NAME) // only used when there's a sql instance
-* sqlIdentityId (IDENTITY_ID) // only used when there's a sql instance
+* sqlServerEndpoint (SQL_ENDPOINT) // only used when there's an sql instance
+* sqlUsername (SQL_USER_NAME) // only used when there's an sql instance
+* sqlPassword (SQL_PASSWORD) // only used when there's an sql instance
+* sqlDatabaseName (SQL_DATABASE_NAME) // only used when there's an sql instance
+* sqlIdentityId (IDENTITY_ID) // only used when there's an sql instance
</details>
If you've created Azure function or bot project using Visual Studio Code Toolkit
Basic type of API error response is `ErrorWithCode`, which contains error code and error message. For example, to filter out specific error, you can use the following snippet:
-```ts
+```typescript
try { const teamsfx = new TeamsFx(); await teamsfx.login("User.Read");
This section provides several code snippets for common scenarios that are relate
1. Import the classes needed.
- ```ts
+ ```typescript
import { createMicrosoftGraphClient, TeamsFx,
This section provides several code snippets for common scenarios that are relate
2. Use `TeamsFx.login()` to get user consent.
- ```ts
+ ```typescript
// Put these code in a call-to-action callback function to avoid browser blocking automatically showing up pop-ups. await teamsfx.login(["User.Read"]); // Login with scope ``` 3. You can initialize a TeamsFx instance and graph client and get information from MS Graph by this client.
- ```ts
+ ```typescript
try { const teamsfx = new TeamsFx(); const graphClient = createMicrosoftGraphClient(teamsfx, ["User.Read"]); // Initializes MS Graph SDK using our MsGraphAuthProvider
This section provides several code snippets for common scenarios that are relate
2. Initialize the provider inside your component.
- ```ts
- // Import the providers and credential at the top of the page
+ ```typescript
+ // Import the providers and credential at the top of the page
import {Providers} from '@microsoft/mgt-element'; import {TeamsFxProvider} from '@microsoft/mgt-teamsfx-provider'; import {TeamsUserCredential} from "@microsoft/teamsfx";
This section provides several code snippets for common scenarios that are relate
const scope = ["User.Read"]; const teamsfx = new TeamsFx(); const provider = new TeamsFxProvider(teamsfx, scope);
- Providers.globalProvider = provider;
+ Providers.globalProvider = provider;
``` 3. You can use the `teamsfx.login(scopes)` method to get required access token.
- ```ts
+ ```typescript
// Put these code in a call-to-action callback function to avoid browser blocking automatically showing up pop-ups. await teamsfx.login(this.scope); Providers.globalProvider.setState(ProviderState.SignedIn);
This section provides several code snippets for common scenarios that are relate
<mgt-person query="me" view="threeLines"></mgt-person> ```
- ```ts
+ ```typescript
public render(): void { return ( <div> <Person personQuery="me" view={PersonViewType.threelines}></Person> </div> );
- }
+ }
``` For more information on sample to initialize the TeamsFx provider, see the [Contacts Exporter sample](https://github.com/OfficeDev/TeamsFx-Samples/tree/dev/graph-toolkit-contact-exporter).
This section provides several code snippets for common scenarios that are relate
1. Initialize and add `TeamsBotSsoPrompt` to dialog set.
- ```ts
+ ```typescript
const { ConversationState, MemoryStorage } = require("botbuilder"); const { DialogSet, WaterfallDialog } = require("botbuilder-dialogs"); const { TeamsBotSsoPrompt } = require("@microsoft/teamsfx");
This section provides several code snippets for common scenarios that are relate
new TeamsBotSsoPrompt(teamsfx, "TeamsBotSsoPrompt", { scopes: ["User.Read"], })
- );
+ );
``` 2. Begin the dialog and sign-in.
- ```ts
+ ```typescript
dialogs.add( new WaterfallDialog("taskNeedingLogin", [ async (step) => {
This section provides several code snippets for common scenarios that are relate
} }, ])
- );
+ );
``` For more information on sample to use graph API in bot application, see [bot-sso sample](https://github.com/OfficeDev/TeamsFx-Samples/tree/dev/bot-sso). </details>
+ <details>
+ <summary><b>Use Graph API in Message Extension</b></summary>
+
+ This code snippet shows you how to override `handleTeamsMessagingExtensionQuery` extends from `TeamsActivityHandler`, and use `handleMessageExtensionQueryWithToken` provided by TeamsFx sdk to sign-in to get an access token:
+
+ ```typescript
+ public async handleTeamsMessagingExtensionQuery(context: TurnContext, query: any): Promise<any> {
+ return await handleMessageExtensionQueryWithToken(context, null, 'User.Read',
+ async (token: MessageExtensionTokenResponse) => {
+ // ... continue to query with access token ...
+ });
+ }
+ ```
+
+ For more information on sample to use graph API in message extension, see [message-extension-sso-sample](https://aka.ms/teamsfx-me-sso-sample).
+ </details>
+
+ <details>
+ <summary><b>Use Graph API in Command Bot</b></summary>
+
+ This code snippet shows you how to implement `TeamsFxBotSsoCommandHandler` for command bot to call Microsoft API.
+
+ ```typescript
+ import { Activity, TurnContext } from "botbuilder";
+ import {
+ CommandMessage,
+ TriggerPatterns,
+ TeamsFx,
+ createMicrosoftGraphClient,
+ TeamsFxBotSsoCommandHandler,
+ TeamsBotSsoPromptTokenResponse,
+ } from "@microsoft/teamsfx";
+
+ export class ProfileSsoCommandHandler implements TeamsFxBotSsoCommandHandler {
+ triggerPatterns: TriggerPatterns = "profile";
+
+ async handleCommandReceived(
+ context: TurnContext,
+ message: CommandMessage,
+ tokenResponse: TeamsBotSsoPromptTokenResponse,
+ ): Promise<string | Partial<Activity> | void> {
+ // Init TeamsFx instance with SSO token
+ const teamsfx = new TeamsFx().setSsoToken(tokenResponse.ssoToken);
+
+ // Add scope for your Azure AD app. For example: Mail.Read, etc.
+ const graphClient = createMicrosoftGraphClient(teamsfx, ["User.Read"]);
+
+ // Call graph api use `graph` instance to get user profile information
+ const me = await graphClient.api("/me").get();
+
+ if (me) {
+ // Bot will send the user profile info to user
+ return `Your command is '${message.text}' and you're logged in as ${me.displayName}`;
+ } else {
+ return "Could not retrieve profile information from Microsoft Graph.";
+ }
+ }
+ }
+ ```
+
+ For more information about how to use this class in command bot, see [Add single sign-on to Teams app](add-single-sign-on.md). And there's also a [command-bot-with-sso](https://github.com/OfficeDev/TeamsFx-Samples/tree/dev/command-bot-with-sso) sample project, which you can try sso command bot.
+
+ </details>
+ <details> <summary><b>Call Azure Function in tab app: On-Behalf-Of flow</b></summary>
This section provides several code snippets for common scenarios that are relate
1. You can use `CreateApiClient` provided by TeamsFx sdk to call Azure Function:
- ```ts
+ ```typescript
async function callFunction(teamsfx?: TeamsFx) { const teamsfx = new TeamsFx();
This section provides several code snippets for common scenarios that are relate
// Send a GET request to "RELATIVE_API_PATH", "/api/functionName" for example. const response = await apiClient.get("RELATIVE_API_PATH"); return response.data;
- }
+ }
``` You can also use `axios` library to call Azure Function.
- ```ts
+ ```typescript
async function callFunction(teamsfx?: TeamsFx) { const accessToken = await teamsfx.getCredential().getToken(""); // Get SSO token // teamsfx.getConfig("apiEndpoint") will read REACT_APP_FUNC_ENDPOINT environment variable
This section provides several code snippets for common scenarios that are relate
}, }); return response.data;
- }
+ }
``` 2. Call Graph API in Azure function on-behalf of user in response.
- ```ts
+ ```typescript
export default async function run( context: Context, req: HttpRequest,
This section provides several code snippets for common scenarios that are relate
} catch (e) { } return res;
- }
+ }
``` For more information on sample to use graph API in bot application, see [hello-world-tab-with-backend sample](https://github.com/OfficeDev/TeamsFx-Samples/tree/dev/hello-world-tab-with-backend).
This section provides several code snippets for common scenarios that are relate
1. You can initialize the `authConfig` by providing a `PEM-encoded key certificate`.
- ```ts
+ ```typescript
const authConfig = { clientId: process.env.M365_CLIENT_ID, certificateContent: "The content of a PEM-encoded public/private key certificate", authorityHost: process.env.M365_AUTHORITY_HOST, tenantId: process.env.M365_TENANT_ID,
- };
+ };
``` 2. You can use the `authConfig` to get the token.
- ```ts
+ ```typescript
const teamsfx = new TeamsFx(IdentityType.App); teamsfx.setCustomeConfig(authConfig);
- const token = teamsfx.getCredential().getToken();
+ const token = teamsfx.getCredential().getToken();
``` </details>
This section provides several code snippets for common scenarios that are relate
1. You can initialize the `authConfig` by providing a `client secret`.
- ```ts
+ ```typescript
const authConfig = { clientId: process.env.M365_CLIENT_ID, clientSecret: process.env.M365_CLIENT_SECRET, authorityHost: process.env.M365_AUTHORITY_HOST, tenantId: process.env.M365_TENANT_ID,
- };
+ };
``` 2. You can use the `authConfig` to get the token.
- ```ts
+ ```typescript
const teamsfx = new TeamsFx(IdentityType.App); teamsfx.setCustomeConfig(authConfig);
- const token = teamsfx.getCredential().getToken();
+ const token = teamsfx.getCredential().getToken();
``` For more information on sample to use graph API in bot application, see the [hello-world-tab-with-backend sample](https://github.com/OfficeDev/TeamsFx-Samples/tree/dev/hello-world-tab-with-backend).
This section provides several code snippets for other scenarios that are related
This code snippet shows you how to call an existing API in Bot by `ApiKeyProvider`.
- ```ts
+ ```typescript
const teamsfx = new TeamsFx(); // Create an API Key auth provider. In addition to APiKeyProvider, following auth providers are also available:
This section provides several code snippets for other scenarios that are related
); // Send a GET request to "RELATIVE_API_PATH", "/api/apiname" for example.
- const response = await apiClient.get("RELATIVE_API_PATH");
+ const response = await apiClient.get("RELATIVE_API_PATH");
``` </details>
This section provides several code snippets for other scenarios that are related
1. Set the connection configuration.
- ```ts
+ ```typescript
// Equivalent to: // const sqlConnectConfig = new DefaultTediousConnectionConfiguration({ // sqlServerEndpoint: process.env.SQL_ENDPOINT,
This section provides several code snippets for other scenarios that are related
// If there's only one SQL database const config = await getTediousConnectionConfig(teamsfx); // If there are multiple SQL databases
- const config2 = await getTediousConnectionConfig(teamsfx, "your database name");
+ const config2 = await getTediousConnectionConfig(teamsfx, "your database name");
``` 2. Connect to your database.
- ```ts
+ ```typescript
const connection = new Connection(config); connection.on("connect", (error) => { if (error) { console.log(error); }
- });
+ });
``` > [!NOTE]
When you set log level then Logging gets enabled. It prints log information to c
Set log level using the following snippet:
-```ts
+```typescript
// Only need the warning and error messages. setLogLevel(LogLevel.Warn); ```
setLogLevel(LogLevel.Warn);
#### Redirect by setting custom logger
-```ts
+```typescript
setLogLevel(LogLevel.Info); // Set another logger if you want to redirect to Application Insights in Azure Function setLogger(context.log);
setLogger(context.log);
#### Redirect by setting custom log function
-```ts
+```typescript
setLogLevel(LogLevel.Info); // Only log error message to Application Insights in bot application. setLogFunction((level: LogLevel, message: string) => {
platform Provision https://github.com/MicrosoftDocs/msteams-docs/commits/main/msteams-platform/toolkit/provision.md
To ensure the TeamsFx tool functions properly, ensure you customize ARM template
You can customize the following scenarios:
-#### Use an existing Azure AD app for your bot
+#### Use an existing Azure AD app for your Teams app
You can add following configuration snippet to `.fx/configs/config.{env}.json` file to use an Azure AD app created by yourself for your Teams app. To create an Azure AD app, see <https://aka.ms/teamsfx-existing-aad-doc>.
After adding the snippet, add your secret to related environment variable so the
> [!NOTE] > Ensure not to share the same Azure AD app in multiple environments. If you don't have permission to update the Azure AD app, you can get a warning with instructions about how to manually update the Azure AD app. Follow the instructions to update your Azure AD app after provision.
-#### Use an existing Azure AD app for your Teams app
+#### Use an existing Azure AD app for your bot
You can add following configuration snippet to `.fx/configs/config.{env}.json` file to use an Azure AD app created by yourself for your bot:
To ensure the TeamsFx tool functions properly, customize ARM template, that sati
You can customize your bot or the Teams app by adding configuration snippets to use an Azure AD app created by you. You can perform in the following ways:
-#### Use an existing Azure AD app for your bot
+#### Use an existing Azure AD app for your Teams app
You can add the following configuration snippet `.fx/configs/config.{env}.json` to use an Azure AD app created by you for your Teams app. To create an Azure AD app, follow the link <https://aka.ms/teamsfx-existing-aad-doc>.
After adding the snippet, add your client secret to the related environment vari
> [!NOTE] > Ensure not to share the same Azure AD app in multiple environments. If you don't have permission to update the Azure AD app, you get a warning with instructions to manually update the Azure AD app. Follow these instructions to update your Azure AD app after provision.
-#### Use an existing Azure AD app for your Teams app
+#### Use an existing Azure AD app for your bot
You can add the following configuration snippet to `.fx/configs/config.{env}.json` to use the Azure AD app created for your bot: