Merk
Tilgang til denne siden krever autorisasjon. Du kan prøve å logge på eller endre kataloger.
Tilgang til denne siden krever autorisasjon. Du kan prøve å endre kataloger.
An agent configuration experience is a settings flow that lets users configure an agent during installation and reconfigure it later in a channel or group chat. Use it to collect the information your agent needs to work with a team's workflows, without asking users to leave Teams. For example, users can choose the news topics or GitHub repositories an agent monitors, then change those settings as their needs change.
Prerequisites
Before you implement the configuration experience, you need:
- An agent project that supports a channel or group chat scope. For more information, see Understand agent concepts.
- Access to the app manifest to update
bots.configuration. - A configuration dialog or Adaptive Card to collect the settings your agent needs. For more information, see Dialogs.
User experience
Users configure the agent when they add it to a channel or group chat. They can later reopen its settings to adapt the agent to changing requirements.
Configure during installation
The following example shows a user adding an agent to a group chat and configuring its settings.
Reconfigure after installation
Users can reopen the configuration experience to change the agent's settings, as shown in the following example.
Users can reopen settings in either of the following ways:
@mention the agent in the message compose area, then select Settings above the compose area. Update the agent's configuration in the dialog that opens.
Hover over the agent to open its profile card, then select the settings icon. Update the agent's configuration in the dialog that opens.
Developer experience
To implement the configuration experience, follow these steps:
Implement agent configuration experience
Support both initial configuration during installation and reconfiguration after installation.
Update app manifest
In the app manifest (previously called Teams app manifest) file, update the fetchTask property under the bots.configuration object as follows:
"bots": [
{
"botId": "${{AAD_APP_CLIENT_ID}}",
"needsChannelSelector": false,
"scopes": [
"personal",
"team",
"groupChat"
],
"configuration":{
"groupChat":{
"fetchTask": true
},
"team":{
"fetchTask": true
}
},
"isNotificationOnly": false
}
],
groupChat.fetchTask— Enables dynamic configuration requests in the group chat scope. Set this totrueso your agent can return a configuration dialog or Adaptive Card.team.fetchTask— Enables dynamic configuration requests in the team channel scope. Set this totrueso channel users can configure your agent.
For more information, see app manifest schema.
Configure your agent
When a user installs the agent in channel or group chat, the fetchTask property in the app manifest file initiates either config.fetch or config.submit.
If you set the fetchTask property in the app manifest to:
false: The agent doesn't fetch a dialog or an Adaptive Card. Instead, the agent must provide a static dialog or card that is used when the agent is invoked. For more information, see dialogs.
true: The agent initiates either
config.fetchorconfig.submitas defined. When the agent is invoked, you can return an Adaptive Card or a dialog depending on the context provided in channelData and userdata.
The following table lists the response type associated with the invoke requests:
| Invoke request | Response type |
|---|---|
config.fetch |
type: "continue" or type: "auth" |
config.submit |
type: "continue" or type: "message" |
Continue the configuration dialog
Use type: "continue" to return a dialog or Adaptive Card when your agent needs more input from the user.
When the user submits the configuration, the config.submit invoke is triggered. Read the user's input and return a different Adaptive Card if more input is needed. You can also return a dialog.
using CardAction = Microsoft.Teams.Cards.Action;
using TaskSize = Microsoft.Teams.Api.TaskModules.Size;
app.OnConfigFetch((context, cancellationToken) =>
{
var card = new AdaptiveCard
{
Body = new List<CardElement>
{
new TextBlock("Configure your agent") { Weight = TextWeight.Bolder }
},
Actions = new List<CardAction>
{
new SubmitAction { Title = "Submit" }
}
};
var taskInfo = new TaskInfo
{
Title = "test card",
Width = new Union<int, TaskSize>(600),
Height = new Union<int, TaskSize>(500),
Card = new Attachment(card)
};
return System.Threading.Tasks.Task.FromResult<ConfigResponse>(
new ConfigTaskResponse(new ContinueTask(taskInfo)));
});
CardActionandTaskSize— Identify the card action and dialog size types. Use the aliasesMicrosoft.Teams.Cards.ActionandMicrosoft.Teams.Api.TaskModules.Sizeso the action list and size unions reference the intended types.TaskInfo.Title— Sets the title shown on the configuration dialog. Set this to"test card"for the sample, or use a title that describes your settings.TaskInfo.WidthandTaskInfo.Height— Set the dimensions of the agent configuration dialog. Set these tonew Union<int, TaskSize>(600)andnew Union<int, TaskSize>(500), respectively, so the sample card has room to display.TaskInfo.Card— Supplies the Adaptive Card shown in the dialog. Set this tonew Attachment(card)so the dialog displays your configuration card.Task.FromResult<ConfigResponse>— Returns the configuration response from the fetch handler. Passnew ConfigTaskResponse(new ContinueTask(taskInfo))so the handler returns a task containing the continuation dialog.
app.on('config.open', async (): Promise<ConfigResponse> => {
const card = new AdaptiveCard({
type: 'TextBlock',
text: 'Configure your agent',
weight: 'Bolder',
}).withActions(
new SubmitAction().withTitle('Submit')
);
return {
responseType: 'config',
config: {
type: 'continue',
value: {
card: cardAttachment('adaptive', card),
height: 500,
width: 600,
title: 'test card',
},
},
};
});
app.onevent — Selects the handler for opening the configuration experience. Set this to'config.open'so the handler returns the initial configuration card.responseType— Identifies the returned payload as a configuration response. Set this to'config'and usePromise<ConfigResponse>as the handler's return type so the response matches the typed configuration contract.config.type— Keeps the configuration interaction open for user input. For example, you can set this to'continue'so Teams displays the configuration card.config.value.card— Supplies the Adaptive Card shown in the dialog. Set this tocardAttachment('adaptive', card)so users can interact with your configuration card.
@app.on_config_open
async def handle_config_open(
ctx: ActivityContext[ConfigFetchInvokeActivity]
) -> ConfigInvokeResponse:
card = AdaptiveCard(
body=[
TextBlock(text="Configure your agent", weight="Bolder")
],
actions=[
SubmitAction(title="Submit")
]
)
return ConfigResponse(
config=TaskModuleContinueResponse(
value=CardTaskModuleTaskInfo(
card=card_attachment(AdaptiveCardAttachment(content=card)),
height=500,
width=600,
title="test card",
)
)
)
card— Supplies the Adaptive Card shown in the dialog. Set this tocard_attachment(AdaptiveCardAttachment(content=card))so users can interact with your configuration card.heightandwidth— Set the dimensions of the agent configuration dialog. Set these to500and600so the sample card has room to display.
Request authentication
Use type: "auth" in a response to config.fetch when your agent requires the user to authenticate. Provide a sign-in URL that opens a valid authentication page in a browser.
Note
type: "auth" supports only third-party authentication, not single sign-on (SSO). For more information, see Add authentication.
app.OnConfigFetch((context, cancellationToken) =>
{
var response = new ConfigAuthResponse(
new ConfigAuth
{
SuggestedActions = new SuggestedActions
{
To = [context.Activity.From.Id],
Actions =
[
new CardAction(ActionType.OpenUrl)
{
Title = "Sign in to this app",
Value = "https://example.com/auth"
}
]
}
});
return System.Threading.Tasks.Task.FromResult<ConfigResponse>(response);
});
app.OnConfigSubmit((context, cancellationToken) =>
{
var response = new ConfigTaskResponse(
new MessageTask("You have chosen to finish setting up agent"));
return System.Threading.Tasks.Task.FromResult<ConfigResponse>(response);
});
SuggestedActions.To— Identifies the user who receives the sign-in action. Set this to[context.Activity.From.Id]so the action targets the user configuring the agent.ActionType.OpenUrl— Specifies the action used to open authentication. Pass this toCardActionso users can open your authentication page.CardAction.Title— Sets the label displayed for the sign-in action. For example, you can set this to"Sign in to this app"so users understand the action.CardAction.Value— Provides the destination URL for the sign-in action. Replace"https://example.com/auth"with your authentication page URL so users reach your service.MessageTaskmessage — Supplies the final message returned by the submit handler. Set this to"You have chosen to finish setting up agent"for the sample, or use a confirmation that describes the result to users.Task.FromResult<ConfigResponse>— Returns a typed response from each configuration handler. Passresponseso the fetch handler returns the authentication response and the submit handler returns the completion message.
app.on('config.open', async ({ activity }): Promise<ConfigResponse> => {
return {
responseType: 'config',
config: {
type: 'auth',
suggestedActions: {
to: [activity.from.id],
actions: [
{
type: 'openUrl',
value: 'https://example.com/auth',
title: 'Sign in to this app',
},
],
},
},
};
});
app.onevent — Selects the handler for opening the configuration experience. Set this to'config.open'so the handler can request authentication.responseType— Identifies the returned payload as a configuration response. Set this to'config'and usePromise<ConfigResponse>as the handler's return type so the response matches the typed configuration contract.config.type— Selects an authentication response for the configuration request. Set this to'auth'so Teams prompts the user to sign in.config.suggestedActions.to— Identifies the user who receives the sign-in action. Set this to[activity.from.id]so the action targets the user configuring the agent.config.suggestedActions.actions[].type— Specifies the action used to open authentication. Set this to'openUrl'so users can open your authentication page.config.suggestedActions.actions[].value— Provides the destination URL for the sign-in action. Replace'https://example.com/auth'with your authentication page URL so users reach your service.
@app.on_config_open
async def handle_config_open(
ctx: ActivityContext[ConfigFetchInvokeActivity]
) -> ConfigInvokeResponse:
return ConfigResponse(
config=ConfigAuth(
suggested_actions=SuggestedActions(
to=[ctx.activity.from_.id],
actions=[
CardAction(
type="openUrl",
value="https://example.com/auth",
title="Sign in to this app",
)
],
)
)
)
type— Specifies the action used to open authentication. Set this to"openUrl"so users can open your authentication page.value— Provides the destination URL for the sign-in action. Set this to your authentication page URL, replacing"https://example.com/auth"so users reach your service.
Complete configuration
Use type: "message" to return a message that ends the interaction or provides information without requesting more input.
app.OnConfigSubmit((context, cancellationToken) =>
{
var response = new ConfigTaskResponse(
new MessageTask("You have chosen to finish setting up agent"));
return System.Threading.Tasks.Task.FromResult<ConfigResponse>(response);
});
MessageTaskmessage — Supplies the final message shown after configuration completes. Set this to"You have chosen to finish setting up agent"for the sample, or use a confirmation that describes the result.Task.FromResult<ConfigResponse>— Returns the completion response from the submit handler. Passresponse, containingConfigTaskResponseandMessageTask, so the handler returns a task containing the final message.
app.on('config.submit', async (): Promise<ConfigResponse> => {
return {
responseType: 'config',
config: {
type: 'message',
value: 'You have chosen to finish setting up agent',
},
};
});
app.onevent — Selects the handler for submitted agent configuration settings. Set this to'config.submit'so the handler returns a completion response.responseType— Identifies the returned payload as a configuration response. Set this to'config'and usePromise<ConfigResponse>as the handler's return type so the response matches the typed configuration contract.config.type— Ends the configuration interaction with a response message. Set this to'message'or this sample so Teams doesn't request more input.config.value— Supplies the final message shown after configuration completes. Set this to'You have chosen to finish setting up agent'for the sample, or use a confirmation that describes the result.
@app.on_config_submit
async def handle_config_submit(
ctx: ActivityContext[ConfigSubmitInvokeActivity]
) -> ConfigInvokeResponse:
return ConfigResponse(
config=TaskModuleMessageResponse(
value="You have chosen to finish setting up agent",
)
)
value— Supplies the final message shown after configuration completes. Set this to"You have chosen to finish setting up agent"for the sample, or use a confirmation that describes the result.
When a user reconfigures the agent, the fetchTask property in the app manifest initiates config.fetch in the agent logic. Use the same handler to support the entry points described in Reconfigure after installation.
Code sample
| Sample name | Description | .NET | Node.js | Manifest |
|---|---|---|---|---|
| Agent configuration app | Configure and reconfigure Adaptive Cards in teams and group chats. | View | View | View |
| Agent configuration app with auth | Configure and reconfigure an agent with dynamic search on Adaptive Cards. | View | View | View |
Design guidelines and best practices
- Track configuration per channel when your agent needs channel-specific settings. Configuration data isn't stored for you. Use the channelData in the invoke payload to identify the channel.
- Provide a clear dialog that asks for the information your agent needs, such as a URL, an area path, or a dashboard link.
- Avoid sending repeated configuration notifications after installation, which can confuse users.
- For an app with both agent and tab capabilities, choose the default landing capability that matches your configuration flow. For more information, see Configure your app's default landing capability.
Limitations and known issues
- The agent configuration experience is supported only in a channel or group chat, not in personal scope.
- Authentication responses support only third-party authentication. SSO isn't supported for
type: "auth". - Your agent is responsible for storing configuration data.