-
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
Mentions scenario #1245
Merged
Merged
Mentions scenario #1245
Changes from all commits
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
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= |
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": "mentions-bot", | ||
"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" | ||
} | ||
} |
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 { MentionsBot } from './mentionsBot'; | ||
|
||
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 MentionsBot(); | ||
|
||
// Listen for incoming requests. | ||
server.post('/api/messages', (req, res) => { | ||
adapter.processActivity(req, res, async (context) => { | ||
// Route to main dialog. | ||
await myBot.run(context); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
libraries/botbuilder/tests/teams/mentionsBot/src/mentionsBot.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,32 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { | ||
Mention, | ||
MessageFactory, | ||
TeamsActivityHandler, | ||
} from 'botbuilder'; | ||
|
||
export class MentionsBot extends TeamsActivityHandler { | ||
/* | ||
* You can @mention the bot from any scope and it will reply with the mention. | ||
*/ | ||
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) => { | ||
var mention = { mentioned: context.activity.from, text:`<at>${context.activity.from.name}</at>` }; | ||
|
||
// Against Teams having a Mention in the Entities but not including that | ||
// mention Text in the Activity Text will result in a BadRequest. | ||
var replyActivity = MessageFactory.text(`Hello ${mention.text}.`); | ||
replyActivity.entities = [ <Mention> mention ]; | ||
|
||
await context.sendActivity(replyActivity); | ||
|
||
// By calling next() you ensure that the next BotHandler is run. | ||
await next(); | ||
}); | ||
} | ||
} |
Binary file added
BIN
+3.12 KB
libraries/botbuilder/tests/teams/mentionsBot/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
libraries/botbuilder/tests/teams/mentionsBot/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.
43 changes: 43 additions & 0 deletions
43
libraries/botbuilder/tests/teams/mentionsBot/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,43 @@ | ||
{ | ||
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.3/MicrosoftTeams.schema.json", | ||
"manifestVersion": "1.3", | ||
"version": "1.0.0", | ||
"id": "<<YOUR_GENERATED_APP_GUID>>", | ||
"packageName": "com.teams.sample.mentionsbot", | ||
"developer": { | ||
"name": "MentionsBot", | ||
"websiteUrl": "https://www.microsoft.com", | ||
"privacyUrl": "https://www.teams.com/privacy", | ||
"termsOfUseUrl": "https://www.teams.com/termsofuser" | ||
}, | ||
"icons": { | ||
"color": "icon-color.png", | ||
"outline": "icon-outline.png" | ||
}, | ||
"name": { | ||
"short": "MentionsBot", | ||
"full": "MentionsBot" | ||
}, | ||
"description": { | ||
"short": "MentionsBot", | ||
"full": "MentionsBot" | ||
}, | ||
"accentColor": "#FFFFFF", | ||
"bots": [ | ||
{ | ||
"botId": "<<YOUR_BOTS_MSA_APP_ID>>", | ||
"scopes": [ | ||
"groupchat", | ||
"team", | ||
"personal" | ||
], | ||
"supportsFiles": false, | ||
"isNotificationOnly": false | ||
} | ||
], | ||
"permissions": [ | ||
"identity", | ||
"messageTeamMembers" | ||
], | ||
"validDomains": [] | ||
} |
11 changes: 11 additions & 0 deletions
11
libraries/botbuilder/tests/teams/mentionsBot/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.
yay, I have started adding this too..