Forum Discussion
Tools in Teams AI Library
Hello Janhvi,
Can you please try to register subhandlers for actions using the Teams AI Library.
import { Application, ApplicationTurnState, PauseParameters } from 'your-teams-ai-library'; // Import necessary types from the Teams AI Library
// Define the JSON data for actions and subactions
const actionsAndSubactions = [
{
"name": "Pause",
"description": "Delays for a period of time",
"subactions": [
{
"name": "Resume",
"description": "Resumes after pause"
},
{
"name": "Stop",
"description": "Stops the pause"
}
]
}
// Add more actions and subactions as needed
];
// Define the subaction handlers
const subactionHandlers: { [name: string]: (context: any, state: ApplicationTurnState, parameters: any) => Promise<string> } = {
async Resume(context: any, state: ApplicationTurnState, parameters: any) {
// Implement logic for handling the Resume subaction
return "Resume logic executed";
},
async Stop(context: any, state: ApplicationTurnState, parameters: any) {
// Implement logic for handling the Stop subaction
return "Stop logic executed";
}
// Add more subaction handlers as needed
};
// Initialize the application
const app = new Application<ApplicationTurnState>({
storage,
ai: {
planner
}
});
// Register action handlers
actionsAndSubactions.forEach(action => {
app.ai.action(action.name, async (context: any, state: ApplicationTurnState, parameters: PauseParameters) => {
const subactionName = context.activity.value?.subaction;
if (subactionName && subactionHandlers[subactionName]) {
return subactionHandlers[subactionName](context, state, parameters);
} else {
await context.sendActivity(`[pausing for ${parameters.time / 1000} seconds]`);
await new Promise((resolve) => setTimeout(resolve, parameters.time));
return `done pausing`;
}
});
});
Thank you so much Vaibhav-MSFT !
Apart from the below two links, where do I find references or document for all of this?
https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/teams%20conversational%20ai/teams-conversation-ai-overview
https://github.com/microsoft/teams-ai/tree/main/js/samples/
Are there any more documentation links?
Also if I want the actions to be performed on some data that I provide, how to achieve that?