-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Missing link unfurling scenario (#1313)
* added linkunfurling back * updated code to match update on handler * Addressed PR comments from stevengum
- Loading branch information
Showing
9 changed files
with
207 additions
and
0 deletions.
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,4 @@ | ||
lib/ | ||
node_modules/ | ||
.vscode/ | ||
**/*.zip |
30 changes: 30 additions & 0 deletions
30
libraries/botbuilder/tests/teams/link-unfurling/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": "teams-link-unfurling", | ||
"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" | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
libraries/botbuilder/tests/teams/link-unfurling/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,51 @@ | ||
// 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 { LinkUnfurlingBot } from './linkUnfurling'; | ||
|
||
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 | ||
}); | ||
|
||
// 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 LinkUnfurlingBot(); | ||
|
||
// Listen for incoming requests. | ||
server.post('/api/messages', (req, res) => { | ||
adapter.processActivity(req, res, async (context) => { | ||
// Route to main dialog. | ||
await myBot.run(context); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
libraries/botbuilder/tests/teams/link-unfurling/src/linkUnfurling.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,45 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { | ||
AppBasedLinkQuery, | ||
CardFactory, | ||
MessagingExtensionResponse, | ||
MessagingExtensionResult, | ||
TeamsActivityHandler, | ||
TurnContext } | ||
from 'botbuilder'; | ||
|
||
export class LinkUnfurlingBot 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(); | ||
}); | ||
} | ||
|
||
// "Link Unfurling" | ||
// This handler is used for the processing of "composeExtension/queryLink" activities from Teams. | ||
// https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/messaging-extensions/search-extensions#receive-requests-from-links-inserted-into-the-compose-message-box | ||
// By specifying domains under the messageHandlers section in the manifest, the bot can receive | ||
// events when a user enters in a domain in the compose box. | ||
protected async onTeamsAppBasedLinkQuery(context: TurnContext, query: AppBasedLinkQuery): Promise<MessagingExtensionResponse> { | ||
const attachment = CardFactory.thumbnailCard('Thumbnail Card', query.url, ["https://raw.githubusercontent.com/microsoft/botframework-sdk/master/icon.png"]); | ||
|
||
const result: MessagingExtensionResult = { | ||
attachmentLayout: 'list', | ||
type: 'result', | ||
attachments: [attachment], | ||
text: 'test unfurl', | ||
} | ||
const response: MessagingExtensionResponse = { | ||
composeExtension: result, | ||
} | ||
|
||
return response; | ||
} | ||
} |
Binary file added
BIN
+1.2 KB
libraries/botbuilder/tests/teams/link-unfurling/teams-app-manifest/color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions
64
libraries/botbuilder/tests/teams/link-unfurling/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,64 @@ | ||
{ | ||
"$schema": "https://github.com/OfficeDev/microsoft-teams-app-schema/blob/preview/DevPreview/MicrosoftTeams.schema.json", | ||
"manifestVersion": "1.5", | ||
"version": "1.0", | ||
"id": "<<MSA BOT ID>>", | ||
"packageName": "com.teams.sample.linkunfurling", | ||
"developer": { | ||
"name": "Link Unfurling1", | ||
"websiteUrl": "https://www.microsoft.com", | ||
"privacyUrl": "https://www.teams.com/privacy", | ||
"termsOfUseUrl": "https://www.teams.com/termsofuser" | ||
}, | ||
"icons": { | ||
"color": "color.png", | ||
"outline": "outline.png" | ||
}, | ||
"name": { | ||
"short": "Link Unfurling1", | ||
"full": "Link Unfurling" | ||
}, | ||
"description": { | ||
"short": "Link Unfurling", | ||
"full": "Link Unfurling" | ||
}, | ||
"accentColor": "#FFFFFF", | ||
"bots": [ | ||
{ | ||
"botId": "<<MSA BOT ID>>", | ||
"scopes": [ "personal", "team" ] | ||
} | ||
], | ||
"composeExtensions": [ | ||
{ | ||
"botId": "<<MSA BOT ID>>", | ||
"commands": [ | ||
{ | ||
"id": "searchQuery", | ||
"context": [ "compose", "commandBox" ], | ||
"description": "Superfluous Test command to enable link unfurling", | ||
"title": "Search", | ||
"type": "query", | ||
"parameters": [ | ||
{ | ||
"name": "searchQuery", | ||
"title": "Search Query", | ||
"description": "Your search query", | ||
"inputType": "text" | ||
} | ||
] | ||
} | ||
], | ||
"messageHandlers": [ | ||
{ | ||
"type": "link", | ||
"value": { | ||
"domains": [ | ||
"*.com" | ||
] | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |
Binary file added
BIN
+383 Bytes
libraries/botbuilder/tests/teams/link-unfurling/teams-app-manifest/outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions
11
libraries/botbuilder/tests/teams/link-unfurling/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", | ||
} | ||
} |