Skip to content

Commit

Permalink
feat: send welcome help card
Browse files Browse the repository at this point in the history
  • Loading branch information
SLdragon committed Jun 28, 2023
1 parent 2686777 commit dac8a89
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/api2teams/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ export async function parseApi(yaml: string, options: CliOptions) {
console.log(` > generate ${apiProviderResult.name} successfully!`);
}

console.log('generate teams bot file');
await fs.copy(
__dirname + '/resources/teamsBotTemplate.txt',
options.output + '/src/teamsBot.ts'
);

console.log('generate index file');
const indexFile = await generateIndexFile(responseCards);
const indexFilePath = path.join(
Expand Down
6 changes: 5 additions & 1 deletion packages/api2teams/src/resources/indexFileTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as restify from "restify";
import { BotBuilderCloudAdapter } from "@microsoft/teamsfx";
import ConversationBot = BotBuilderCloudAdapter.ConversationBot;
import { TeamsBot } from "./teamsBot";

{{importStatements}}

Expand Down Expand Up @@ -34,6 +35,9 @@ server.listen(process.env.port || process.env.PORT || 3978, () => {
// The Teams Toolkit bot registration configures the bot with `/api/messages` as the
// Bot Framework endpoint. If you customize this route, update the Bot registration
// in `templates/azure/provision/botservice.bicep`.
const teamsBot = new TeamsBot();
server.post("/api/messages", async (req, res) => {
await commandBot.requestHandler(req, res);
await commandBot.requestHandler(req, res, async (context) => {
await teamsBot.run(context);
});
});
28 changes: 28 additions & 0 deletions packages/api2teams/src/resources/teamsBotTemplate.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { MessageBuilder } from "@microsoft/teamsfx";
import { TeamsActivityHandler } from "botbuilder";
import helpCard from "./adaptiveCards/helpCard.json";

// An empty teams activity handler.
// You can add your customization code here to extend your bot logic if needed.
export class TeamsBot extends TeamsActivityHandler {
constructor() {
super();
this.onMembersAdded(async (context, next) => {
if (context.activity.membersAdded) {
// Iterate over all new members added to the conversation
for (const member of context.activity.membersAdded) {
// Greet anyone that was not the target (recipient) of this message.
// Since the bot is the recipient for events from the channel,
// context.activity.membersAdded === context.activity.recipient.Id indicates the
// bot was added to the conversation, and the opposite indicates this is a user.
if (member.id !== context.activity.recipient.id) {
await context.sendActivity(MessageBuilder.attachAdaptiveCardWithoutData(helpCard));
}
}
}

// By calling next() you ensure that the next BotHandler is run.
await next();
});
}
}

0 comments on commit dac8a89

Please sign in to comment.