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`;
}
});
});
The code line
const subactionName = context.activity.value?.subaction;
that you mentioned in the above code, doesn't work as context.activity.value is undefined
I checked it with the latest version as well.
Also where will I find the above reference code?
- Vaibhav-MSFTMay 15, 2024Microsoft
Hi Janhvi,
The context.activity.value "undefined" indicates that activity received by the bot does not contain a value property.
Can you add a check before for handling this-
// Check if context.activity.value exists and has a subaction propertyif (context.activity.value && context.activity.value.subaction)
{
subactionName = context.activity.value.subaction;
}- JanhviMay 15, 2024Copper ContributorHello Vaibhav-MSFT
context.activity.value does not exist.
Hence it will never be able to perform the function provided for any subaction- Vaibhav-MSFTMay 16, 2024Microsoft
Janhvi ,
We are in conversation with engineering team and will update you once we get more information on this.