Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 178d266

Browse files
author
Eric Dahlvang
committed
update TeamsConversationBot
1 parent 2b87a29 commit 178d266

1 file changed

Lines changed: 32 additions & 35 deletions

File tree

samples/57.teams-conversation-bot/src/main/java/com/microsoft/bot/sample/teamsconversation/TeamsConversationBot.java

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,7 @@ protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {
7878
{
7979
setTitle("Welcome Card");
8080
setText("Click the buttons below to update this card");
81-
setButtons(Arrays.asList(new CardAction() {
82-
{
83-
setType(ActionTypes.MESSAGE_BACK);
84-
setTitle("Update Card");
85-
setText("UpdateCardAction");
86-
setValue(value);
87-
}
88-
}, new CardAction() {
89-
{
90-
setType(ActionTypes.MESSAGE_BACK);
91-
setTitle("Message All Members");
92-
setText("MessageAllMembers");
93-
}
94-
}));
81+
setButtons(getHeroCardButtons(value));
9582
}
9683
};
9784

@@ -189,26 +176,7 @@ private CompletableFuture<Void> updateCardActivity(TurnContext turnContext) {
189176
{
190177
setTitle("Welcome Card");
191178
setText("Update count - " + data.get("count"));
192-
setButtons(Arrays.asList(new CardAction() {
193-
{
194-
setType(ActionTypes.MESSAGE_BACK);
195-
setTitle("Update Card");
196-
setText("UpdateCardAction");
197-
setValue(data);
198-
}
199-
}, new CardAction() {
200-
{
201-
setType(ActionTypes.MESSAGE_BACK);
202-
setTitle("Message All Members");
203-
setText("MessageAllMembers");
204-
}
205-
}, new CardAction() {
206-
{
207-
setType(ActionTypes.MESSAGE_BACK);
208-
setTitle("Delete card");
209-
setText("Delete");
210-
}
211-
}));
179+
setButtons(getHeroCardButtons(data));
212180
}
213181
};
214182

@@ -218,14 +186,43 @@ private CompletableFuture<Void> updateCardActivity(TurnContext turnContext) {
218186
return turnContext.updateActivity(updatedActivity).thenApply(resourceResponse -> null);
219187
}
220188

189+
private List<CardAction> getHeroCardButtons(Object value) {
190+
return Arrays.asList(new CardAction() {
191+
{
192+
setType(ActionTypes.MESSAGE_BACK);
193+
setTitle("Update Card");
194+
setText("UpdateCardAction");
195+
setValue(value);
196+
}
197+
}, new CardAction() {
198+
{
199+
setType(ActionTypes.MESSAGE_BACK);
200+
setTitle("Message All Members");
201+
setText("MessageAllMembers");
202+
}
203+
}, new CardAction() {
204+
{
205+
setType(ActionTypes.MESSAGE_BACK);
206+
setTitle("Delete card");
207+
setText("Delete");
208+
}
209+
}, new CardAction() {
210+
{
211+
setType(ActionTypes.MESSAGE_BACK);
212+
setTitle("Who am I?");
213+
setText("MentionMe");
214+
}
215+
});
216+
}
217+
221218
private CompletableFuture<Void> mentionActivity(TurnContext turnContext) {
222219
Mention mention = new Mention();
223220
mention.setMentioned(turnContext.getActivity().getFrom());
224221
mention.setText(
225222
"<at>" + URLEncoder.encode(turnContext.getActivity().getFrom().getName()) + "</at>"
226223
);
227224

228-
Activity replyActivity = MessageFactory.text("Hello " + mention.getText() + ".'");
225+
Activity replyActivity = MessageFactory.text("Hello " + mention.getText() + ".");
229226
replyActivity.setMentions(Collections.singletonList(mention));
230227

231228
return turnContext.sendActivity(replyActivity).thenApply(resourceResponse -> null);

0 commit comments

Comments
 (0)