Düğmeler, kullanıcının klavyeyle yanıt yazmak zorunda kalmadan bir soruyu yanıtlamasına veya istenen düğmeyi seçmesine izin vererek konuşma deneyimini geliştirir. Zengin kartlarda görünen düğmelerin aksine (seçildikten sonra bile kullanıcı tarafından görünür ve erişilebilir durumda kalır), kullanıcı seçim yaptıktan sonra önerilen eylemler bölmesinde görünen düğmeler kaybolur. Bu, kullanıcının konuşmadaki eski düğmeleri seçmesini engeller ve bot geliştirmeyi basitleştirir çünkü bu senaryoyu hesaba katın.
Not
Bot Framework JavaScript, C# ve Python SDK'ları desteklenmeye devam edecektir, ancak Java SDK'sı son uzun vadeli destek Kasım 2023'te sona erecek şekilde kullanımdan kaldırılacaktır.
Java SDK ile oluşturulan mevcut botlar çalışmaya devam edecektir.
Yeni bot derlemesi için Power Virtual Agents'ı kullanmayı göz önünde bulundurun ve doğru sohbet botu çözümünü seçme hakkında bilgi edinin.
Önerilen eylemler botunuzun düğmeleri sunmasını sağlar. Kullanıcıya konuşmanın tek bir dönüşü için gösterilecek önerilen eylemlerin (hızlı yanıtlar olarak da bilinir) listesini oluşturabilirsiniz.
Aşağıda Önerilen eylemler örneğinden bir örnek verilmiştır.
// Creates and sends an activity with suggested actions to the user. When the user
// clicks one of the buttons the text value from the "CardAction" will be
// displayed in the channel just as if the user entered the text. There are multiple
// "ActionTypes" that may be used for different situations.
private static async Task SendSuggestedActionsAsync(ITurnContext turnContext, CancellationToken cancellationToken)
{
var reply = MessageFactory.Text("What is your favorite color?");
reply.SuggestedActions = new SuggestedActions()
{
Actions = new List<CardAction>()
{
new CardAction() { Title = "Red", Type = ActionTypes.ImBack, Value = "Red", Image = "https://via.placeholder.com/20/FF0000?text=R", ImageAltText = "R" },
new CardAction() { Title = "Yellow", Type = ActionTypes.ImBack, Value = "Yellow", Image = "https://via.placeholder.com/20/FFFF00?text=Y", ImageAltText = "Y" },
new CardAction() { Title = "Blue", Type = ActionTypes.ImBack, Value = "Blue", Image = "https://via.placeholder.com/20/0000FF?text=B", ImageAltText = "B" },
},
};
await turnContext.SendActivityAsync(reply, cancellationToken);
}
Aşağıda Önerilen eylemler örneğinden bir örnek verilmiştır.
/**
* Send suggested actions to the user.
* @param {TurnContext} turnContext A TurnContext instance containing all the data needed for processing this conversation turn.
*/
async sendSuggestedActions(turnContext) {
const cardActions = [
{
type: ActionTypes.PostBack,
title: 'Red',
value: 'Red',
image: 'https://via.placeholder.com/20/FF0000?text=R',
imageAltText: 'R'
},
{
type: ActionTypes.PostBack,
title: 'Yellow',
value: 'Yellow',
image: 'https://via.placeholder.com/20/FFFF00?text=Y',
imageAltText: 'Y'
},
{
type: ActionTypes.PostBack,
title: 'Blue',
value: 'Blue',
image: 'https://via.placeholder.com/20/0000FF?text=B',
imageAltText: 'B'
}
];
var reply = MessageFactory.suggestedActions(cardActions, 'What is the best color?');
await turnContext.sendActivity(reply);
}
Aşağıda Önerilen eylemler örneğinden bir örnek verilmiştır.
/**
* Creates and sends an activity with suggested actions to the user. When the user
* clicks one of the buttons the text value from the "CardAction" will be
* displayed in the channel just as if the user entered the text. There are multiple
* "ActionTypes" that may be used for different situations.
*/
private static CompletableFuture<Void> sendSuggestedActions(TurnContext turnContext) {
Activity reply = MessageFactory.text("What is your favorite color?");
CardAction redAction = new CardAction();
redAction.setTitle("Red");
redAction.setType(ActionTypes.IM_BACK);
redAction.setValue("Red");
redAction.setImage("https://via.placeholder.com/20/FF0000?text=R");
redAction.setImageAltText("R");
CardAction yellowAction = new CardAction();
yellowAction.setTitle("Yellow");
yellowAction.setType(ActionTypes.IM_BACK);
yellowAction.setValue("Yellow");
yellowAction.setImage("https://via.placeholder.com/20/FFFF00?text=Y");
yellowAction.setImageAltText("Y");
CardAction blueAction = new CardAction();
blueAction.setTitle("Blue");
blueAction.setType(ActionTypes.IM_BACK);
blueAction.setValue("Blue");
blueAction.setImage("https://via.placeholder.com/20/0000FF?text=B");
blueAction.setImageAltText("B");
SuggestedActions actions = new SuggestedActions();
actions.setActions(Arrays.asList(redAction, yellowAction, blueAction));
reply.setSuggestedActions(actions);
return turnContext.sendActivity(reply).thenApply(sendResult -> null);
}
Aşağıda Önerilen eylemler örneğinden bir örnek verilmiştır.
async def _send_suggested_actions(self, turn_context: TurnContext):
"""
Creates and sends an activity with suggested actions to the user. When the user
clicks one of the buttons the text value from the "CardAction" will be displayed
in the channel just as if the user entered the text. There are multiple
"ActionTypes" that may be used for different situations.
"""
reply = MessageFactory.text("What is your favorite color?")
reply.suggested_actions = SuggestedActions(
actions=[
CardAction(
title="Red",
type=ActionTypes.im_back,
value="Red",
image="https://via.placeholder.com/20/FF0000?text=R",
image_alt_text="R",
),
CardAction(
title="Yellow",
type=ActionTypes.im_back,
value="Yellow",
image="https://via.placeholder.com/20/FFFF00?text=Y",
image_alt_text="Y",
),
CardAction(
title="Blue",
type=ActionTypes.im_back,
value="Blue",
image="https://via.placeholder.com/20/0000FF?text=B",
image_alt_text="B",
),
]
)
return await turn_context.send_activity(reply)
Ek kaynaklar
C#, JavaScript, Java ve Python'da Önerilen eylemler örneğinin tam kaynak koduna erişebilirsiniz.