-
Notifications
You must be signed in to change notification settings - Fork 281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add actionBasedMessagingExtension from samples repo, update .gitignore #1225
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
libraries/botbuilder/tests/teams/messaging-extension-action/.env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
MicrosoftAppId= | ||
MicrosoftAppPassword= |
4 changes: 4 additions & 0 deletions
4
libraries/botbuilder/tests/teams/messaging-extension-action/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
lib/ | ||
node_modules/ | ||
.vscode/ | ||
**/*.zip |
30 changes: 30 additions & 0 deletions
30
libraries/botbuilder/tests/teams/messaging-extension-action/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "messaging-extension-action", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
"start": "tsc --build && node ./lib/index.js", | ||
"build": "tsc --build", | ||
"watch": "nodemon --watch ./src -e ts --exec \"npm run start\"" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"botbuilder": "file:../../../", | ||
"dotenv": "^8.1.0", | ||
"node-fetch": "^2.6.0", | ||
"restify": "^8.4.0", | ||
"uuid": "^3.3.3" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^12.7.1", | ||
"@types/node-fetch": "^2.5.0", | ||
"@types/request": "^2.48.1", | ||
"@types/restify": "^7.2.7", | ||
"nodemon": "^1.19.1", | ||
"ts-node": "^7.0.1", | ||
"typescript": "^3.2.4" | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
libraries/botbuilder/tests/teams/messaging-extension-action/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { config } from 'dotenv'; | ||
import * as path from 'path'; | ||
import * as restify from 'restify'; | ||
|
||
// Import required bot services. | ||
// See https://aka.ms/bot-services to learn more about the different parts of a bot. | ||
import { BotFrameworkAdapter } from 'botbuilder'; | ||
|
||
// This bot's main dialog. | ||
import { TeamsActionExtensionBot } from './teamsActionExtensionBot'; | ||
|
||
const ENV_FILE = path.join(__dirname, '..', '.env'); | ||
config({ path: ENV_FILE }); | ||
|
||
// Create HTTP server. | ||
const server = restify.createServer(); | ||
server.listen(process.env.port || process.env.PORT || 3978, () => { | ||
console.log(`\n${server.name} listening to ${server.url}`); | ||
console.log(`\nGet Bot Framework Emulator: https://aka.ms/botframework-emulator`); | ||
console.log(`\nTo test your bot, see: https://aka.ms/debug-with-emulator`); | ||
}); | ||
|
||
// Create adapter. | ||
// See https://aka.ms/about-bot-adapter to learn more about adapters. | ||
const adapter = new BotFrameworkAdapter({ | ||
appId: process.env.MicrosoftAppId, | ||
appPassword: process.env.MicrosoftAppPassword | ||
}); | ||
|
||
// adapter.use(new TranscriptLoggerMiddleware(new FileTranscriptStore('./transcripts'))); | ||
|
||
// Catch-all for errors. | ||
adapter.onTurnError = async (context, error) => { | ||
// This check writes out errors to console log .vs. app insights. | ||
console.error('[onTurnError]:'); | ||
console.error(error); | ||
// Send a message to the user | ||
await context.sendActivity(`Oops. Something went wrong in the bot!\n ${error.message}`); | ||
}; | ||
|
||
// Create the main dialog. | ||
const myBot = new TeamsActionExtensionBot(); | ||
|
||
// Listen for incoming requests. | ||
server.post('/api/messages', (req, res) => { | ||
adapter.processActivity(req, res, async (context) => { | ||
// Route to main dialog. | ||
await myBot.run(context); | ||
}); | ||
}); |
207 changes: 207 additions & 0 deletions
207
libraries/botbuilder/tests/teams/messaging-extension-action/src/teamsActionExtensionBot.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { | ||
MessagingExtensionActionResponse, | ||
MessagingExtensionAction, | ||
TaskModuleContinueResponse, | ||
TaskModuleMessageResponse, | ||
TaskModuleResponseBase, | ||
TeamsActivityHandler, | ||
} from 'botbuilder'; | ||
|
||
import { | ||
Activity, | ||
Attachment, | ||
CardFactory | ||
} from 'botbuilder'; | ||
|
||
export class TeamsActionExtensionBot extends TeamsActivityHandler { | ||
constructor() { | ||
super(); | ||
|
||
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types. | ||
this.onMessage(async (context, next) => { | ||
await context.sendActivity(`You said '${context.activity.text}'`); | ||
// By calling next() you ensure that the next BotHandler is run. | ||
await next(); | ||
}); | ||
|
||
this.onMembersAdded(async (context, next) => { | ||
const membersAdded = context.activity.membersAdded; | ||
for (const member of membersAdded) { | ||
if (member.id !== context.activity.recipient.id) { | ||
await context.sendActivity('Hello and welcome!'); | ||
} | ||
} | ||
|
||
// By calling next() you ensure that the next BotHandler is run. | ||
await next(); | ||
}); | ||
|
||
// This method fires when an user uses an Action-based Messaging Extension from the Teams Client. | ||
// It should send back the tab or task module for the user to interact with. | ||
this.onMessagingExtensionFetchTask(async (context, value, next) => { | ||
return { | ||
status: 200, | ||
body: { | ||
task: this.taskModuleResponse(value, false) | ||
} | ||
}; | ||
}); | ||
|
||
this.onBotMessagePreviewEdit(async (context, value: MessagingExtensionAction, next) => { | ||
const card = this.getCardFromPreviewMessage(value); | ||
let body: MessagingExtensionActionResponse; | ||
if (!card) { | ||
body = { | ||
task: <TaskModuleMessageResponse>{ | ||
type: 'message', | ||
value: 'Missing user edit card. Something wrong on Teams client.' | ||
} | ||
} | ||
} else { | ||
body = { | ||
task: <TaskModuleContinueResponse>{ | ||
type: 'continue', | ||
value: { card } | ||
} | ||
} | ||
} | ||
|
||
return { status: 200, body }; | ||
}); | ||
|
||
this.onBotMessagePreviewSend(async (context, value: MessagingExtensionAction, next) => { | ||
let body: MessagingExtensionActionResponse; | ||
const card = this.getCardFromPreviewMessage(value); | ||
if (!card) { | ||
body = { | ||
task: <TaskModuleMessageResponse>{ | ||
type: 'message', | ||
value: 'Missing user edit card. Something wrong on Teams client.' | ||
} | ||
} | ||
} else { | ||
body = undefined; | ||
await context.sendActivity({ attachments: [card] }); | ||
} | ||
|
||
return { status: 200, body }; | ||
}); | ||
|
||
this.onMessagingExtensionSubmit(async (context, value: MessagingExtensionAction, next) => { | ||
const data = value.data; | ||
let body: MessagingExtensionActionResponse; | ||
if (data && data.done) { | ||
// The commandContext check doesn't need to be used in this scenario as the manifest specifies the shareMessage command only works in the "message" context. | ||
let sharedMessage = (value.commandId === 'shareMessage' && value.commandContext === 'message') | ||
? `Shared message: <div style="background:#F0F0F0">${JSON.stringify(value.messagePayload)}</div><br/>` | ||
: ''; | ||
let preview = CardFactory.thumbnailCard('Created Card', `Your input: ${data.userText}`); | ||
let heroCard = CardFactory.heroCard('Created Card', `${sharedMessage}Your input: <pre>${data.userText}</pre>`); | ||
body = { | ||
composeExtension: { | ||
type: 'result', | ||
attachmentLayout: 'list', | ||
attachments: [ | ||
{ ...heroCard, preview } | ||
] | ||
} | ||
} | ||
} else if (value.commandId === 'createWithPreview') { | ||
const activityPreview = { | ||
attachments: [ | ||
this.taskModuleResponseCard(value) | ||
] | ||
} as Activity; | ||
|
||
body = { | ||
composeExtension: { | ||
type: 'botMessagePreview', | ||
activityPreview | ||
} | ||
}; | ||
} else { | ||
body = { | ||
task: this.taskModuleResponse(value, false) | ||
} | ||
} | ||
|
||
return { status: 200, body }; | ||
}); | ||
} | ||
|
||
private getCardFromPreviewMessage(query: MessagingExtensionAction): Attachment { | ||
const userEditActivities = query.botActivityPreview; | ||
return userEditActivities | ||
&& userEditActivities[0] | ||
&& userEditActivities[0].attachments | ||
&& userEditActivities[0].attachments[0]; | ||
} | ||
|
||
private taskModuleResponse(query: any, done: boolean): TaskModuleResponseBase { | ||
if (done) { | ||
return <TaskModuleMessageResponse>{ | ||
type: 'message', | ||
value: 'Thanks for your inputs!' | ||
} | ||
} else { | ||
return <TaskModuleContinueResponse>{ | ||
type: 'continue', | ||
value: { | ||
title: 'More Page', | ||
card: this.taskModuleResponseCard(query, (query.data && query.data.userText) || undefined) | ||
} | ||
}; | ||
} | ||
} | ||
|
||
private taskModuleResponseCard(data: any, textValue?: string) { | ||
return CardFactory.adaptiveCard({ | ||
version: '1.0.0', | ||
type: 'AdaptiveCard', | ||
body: [ | ||
{ | ||
type: 'TextBlock', | ||
text: `Your request:`, | ||
size: 'large', | ||
weight: 'bolder' | ||
}, | ||
{ | ||
type: 'Container', | ||
style: 'emphasis', | ||
items: [ | ||
{ | ||
type: 'TextBlock', | ||
text: JSON.stringify(data), | ||
wrap: true | ||
} | ||
] | ||
}, | ||
{ | ||
type: 'Input.Text', | ||
id: 'userText', | ||
placeholder: 'Type text here...', | ||
value: textValue | ||
} | ||
], | ||
actions: [ | ||
{ | ||
type: 'Action.Submit', | ||
title: 'Next', | ||
data: { | ||
done: false | ||
} | ||
}, | ||
{ | ||
type: 'Action.Submit', | ||
title: 'Submit', | ||
data: { | ||
done: true | ||
} | ||
} | ||
] | ||
}) | ||
} | ||
} |
Binary file added
BIN
+3.12 KB
...uilder/tests/teams/messaging-extension-action/teams-app-manifest/icon-color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+526 Bytes
...lder/tests/teams/messaging-extension-action/teams-app-manifest/icon-outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions
80
libraries/botbuilder/tests/teams/messaging-extension-action/teams-app-manifest/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"$schema": "https://github.com/OfficeDev/microsoft-teams-app-schema/blob/preview/DevPreview/MicrosoftTeams.schema.json", | ||
"manifestVersion": "devPreview", | ||
"version": "1.0", | ||
"id": "<<YOUR_GENERATED_APP_GUID>>", | ||
"packageName": "com.microsoft.teams.samples.v4bot", | ||
"developer": { | ||
"name": "Microsoft Corp", | ||
"websiteUrl": "https://example.azurewebsites.net", | ||
"privacyUrl": "https://example.azurewebsites.net/privacy", | ||
"termsOfUseUrl": "https://example.azurewebsites.net/termsofuse" | ||
}, | ||
"name": { | ||
"short": "messaging-extension-action", | ||
"full": "Microsoft Teams V4 Action Messaging Extension Bot - C#" | ||
}, | ||
"description": { | ||
"short": "Microsoft Teams V4 Action Messaging Extension Bot - C#", | ||
"full": "Sample Action Messaging Extension Bot using V4 Bot Builder SDK and V4 Microsoft Teams Extension SDK" | ||
}, | ||
"icons": { | ||
"outline": "icon-outline.png", | ||
"color": "icon-color.png" | ||
}, | ||
"accentColor": "#0080FF", | ||
"bots": [], | ||
"composeExtensions": [ | ||
{ | ||
"botId": "<<YOUR_BOTS_MSA_APP_ID>>", | ||
"commands": [ | ||
{ | ||
"id": "createCard", | ||
"type": "action", | ||
"description": "Test command to run action to create a card from Compose Box or Command Bar", | ||
"title": "Create card - manifest params", | ||
"parameters": [ | ||
{ | ||
"name": "title", | ||
"title": "Title parameter", | ||
"description": "Text for title in Hero Card", | ||
"inputType": "text" | ||
}, | ||
{ | ||
"name": "subtitle", | ||
"title": "Subtitle parameter", | ||
"description": "Text for subtitle in Hero Card", | ||
"inputType": "text" | ||
}, | ||
{ | ||
"name": "text", | ||
"title": "Body text", | ||
"description": "Text for body in Hero Card", | ||
"inputType": "text" | ||
} | ||
] | ||
}, | ||
{ | ||
"id": "shareMessage", | ||
"type": "action", | ||
"context": [ "message" ], | ||
"description": "Test command to run action on message context (message sharing)", | ||
"title": "Share Message", | ||
"parameters": [ | ||
{ | ||
"name": "includeImage", | ||
"title": "Include Image", | ||
"description": "Include image in Hero Card", | ||
"inputType": "toggle" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"validDomains": [ | ||
"*.ngrok.io", | ||
"*.azurewebsites.net", | ||
"*.example.com" | ||
] | ||
} |
11 changes: 11 additions & 0 deletions
11
libraries/botbuilder/tests/teams/messaging-extension-action/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"composite": true, | ||
"declaration": true, | ||
"sourceMap": true, | ||
"outDir": "./lib", | ||
"rootDir": "./src", | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bot is called ActionBasedMessagingExtensionBot on C# side, shall we keep them consistent naming wise? Perhaps renamed the C# one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll rename this one to ActionBasedMessagingBot, to keep it consistent with the already checked-in scenario in C#. I'm going to add
*.zip
files to the .gitignore in this PR so we don't check in any zipped up manifests with credentials