From d0922e5b8bc375efbfc3f9b09a20f1ab11f714c2 Mon Sep 17 00:00:00 2001 From: Tien Suwandy Date: Tue, 15 Oct 2019 15:08:54 -0700 Subject: [PATCH 1/3] added linkunfurling back --- .../tests/teams/link-unfurling/.env | 2 + .../tests/teams/link-unfurling/.gitignore | 4 ++ .../tests/teams/link-unfurling/package.json | 30 ++++++++ .../tests/teams/link-unfurling/src/index.ts | 53 +++++++++++++++ .../teams/link-unfurling/src/linkUnfurling.ts | 55 +++++++++++++++ .../teams-app-manifest/color.png | Bin 0 -> 1229 bytes .../teams-app-manifest/manifest.json | 64 ++++++++++++++++++ .../teams-app-manifest/outline.png | Bin 0 -> 383 bytes .../tests/teams/link-unfurling/tsconfig.json | 11 +++ 9 files changed, 219 insertions(+) create mode 100644 libraries/botbuilder/tests/teams/link-unfurling/.env create mode 100644 libraries/botbuilder/tests/teams/link-unfurling/.gitignore create mode 100644 libraries/botbuilder/tests/teams/link-unfurling/package.json create mode 100644 libraries/botbuilder/tests/teams/link-unfurling/src/index.ts create mode 100644 libraries/botbuilder/tests/teams/link-unfurling/src/linkUnfurling.ts create mode 100644 libraries/botbuilder/tests/teams/link-unfurling/teams-app-manifest/color.png create mode 100644 libraries/botbuilder/tests/teams/link-unfurling/teams-app-manifest/manifest.json create mode 100644 libraries/botbuilder/tests/teams/link-unfurling/teams-app-manifest/outline.png create mode 100644 libraries/botbuilder/tests/teams/link-unfurling/tsconfig.json diff --git a/libraries/botbuilder/tests/teams/link-unfurling/.env b/libraries/botbuilder/tests/teams/link-unfurling/.env new file mode 100644 index 0000000000..e4e8ba5564 --- /dev/null +++ b/libraries/botbuilder/tests/teams/link-unfurling/.env @@ -0,0 +1,2 @@ +MicrosoftAppId=cd59cf47-aca1-41e0-8441-387faee8331e +MicrosoftAppPassword=5eM32I/C1]Nh=KIOlnLQUKX@Y10QX44i diff --git a/libraries/botbuilder/tests/teams/link-unfurling/.gitignore b/libraries/botbuilder/tests/teams/link-unfurling/.gitignore new file mode 100644 index 0000000000..a6d1e8839d --- /dev/null +++ b/libraries/botbuilder/tests/teams/link-unfurling/.gitignore @@ -0,0 +1,4 @@ +lib/ +node_modules/ +.vscode/ +**/*.zip \ No newline at end of file diff --git a/libraries/botbuilder/tests/teams/link-unfurling/package.json b/libraries/botbuilder/tests/teams/link-unfurling/package.json new file mode 100644 index 0000000000..8cf8e224ce --- /dev/null +++ b/libraries/botbuilder/tests/teams/link-unfurling/package.json @@ -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" + } +} diff --git a/libraries/botbuilder/tests/teams/link-unfurling/src/index.ts b/libraries/botbuilder/tests/teams/link-unfurling/src/index.ts new file mode 100644 index 0000000000..c2f4cdb4fc --- /dev/null +++ b/libraries/botbuilder/tests/teams/link-unfurling/src/index.ts @@ -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 { 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 +}); + +// 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 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); + }); +}); diff --git a/libraries/botbuilder/tests/teams/link-unfurling/src/linkUnfurling.ts b/libraries/botbuilder/tests/teams/link-unfurling/src/linkUnfurling.ts new file mode 100644 index 0000000000..69bc3b9fa0 --- /dev/null +++ b/libraries/botbuilder/tests/teams/link-unfurling/src/linkUnfurling.ts @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +import { + MessagingExtensionResponse, + MessagingExtensionResult, + TeamsActivityHandler, + InvokeResponseTyped, + CardFactory, + ThumbnailCard, + CardImage, + HeroCard } +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}'`); + await context.sendActivity(`Second response! '${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. + this.onAppBasedLinkQuery(async (context, query, next) => { + 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, + } + + const invoke_response: InvokeResponseTyped = { + status: 200, + body: response, + }; + // For Invoke activities from Teams, we're currently not continuing the chain of handlers. + // await next(); + return Promise.resolve(invoke_response); + + }); + } +} diff --git a/libraries/botbuilder/tests/teams/link-unfurling/teams-app-manifest/color.png b/libraries/botbuilder/tests/teams/link-unfurling/teams-app-manifest/color.png new file mode 100644 index 0000000000000000000000000000000000000000..48a2de13303e1e8a25f76391f4a34c7c4700fd3d GIT binary patch literal 1229 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7OGojKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCe1|JzX3_D&pSWuFnWfl{x;g|9jrEYf8Vqrkk2Ba|%ol3OT){=#|7ID~|e{ zODQ{kU&ME#@`*-tm%Tukt_gFr+`F?$dx9wg-jad`^gsMn2_%Kh%WH91&SjKq5 zgkdI|!exdOVgw@>>=!Tjnk6q)zV*T8$FdgRFYC{kQ7``NOcl@R(_%_8e5e0E;>v0G zEM9kb)2itgOTSfH7M=b3-S61B?PiazMdwXZwrS)^5UUS#HQjaoua5h_{Gx*_Zz|XK z$tf0mZ&=tpf2!!Q)!A_l&o_$g*|JM$VZa~F^0{x1T{=QFu*x$`=V%~jUW=G`iqqp=lquB-`P{Qjw`=zEu3cMc_x7m2f#9m}uoFBMMQ^+%cOL)F_)N@JZ}Axoxi1y= zeebq`y==e!nl+?cK-PhOec!3%|IupShHrcjW8sSt)F1>NW*{ zW%ljk2)nk%-}+F&?gi=7^$L#VeX3@kp%f{n}fR z`}uZPx$IY~r8R5%gMlrc`jP!L3IloKFoq~sFFH5|cdklX=R08T)}71BhaN8$`AsNf0_ zq>WNhAtCd|-nBlTU=y5zl_vXlXZ~bkuaYENMp>3QSQ_#zuYZ+eQh*OIHRxP~s(}ic zN2J4$u=AQcPt)|>F3zZLsjtP;Tajkugx;NcYED2~JVBlVO>{`uAY?Q4O|AA z=16}CJieK^5P_TKnou!zGR`$!PUC)DqtkO;?!`p!+9v3lP_mu=%Vt3BkoWsq%;FN1sp58w*zfr-z^7tIb*q>!yncCjrzLuOk3N+d&~^Cxd| z Date: Tue, 15 Oct 2019 17:06:02 -0700 Subject: [PATCH 2/3] updated code to match update on handler --- .../tests/teams/link-unfurling/.env | 4 +-- .../teams/link-unfurling/src/linkUnfurling.ts | 28 ++++++++----------- .../teams-app-manifest/manifest.json | 6 ++-- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/libraries/botbuilder/tests/teams/link-unfurling/.env b/libraries/botbuilder/tests/teams/link-unfurling/.env index e4e8ba5564..a695b3bf05 100644 --- a/libraries/botbuilder/tests/teams/link-unfurling/.env +++ b/libraries/botbuilder/tests/teams/link-unfurling/.env @@ -1,2 +1,2 @@ -MicrosoftAppId=cd59cf47-aca1-41e0-8441-387faee8331e -MicrosoftAppPassword=5eM32I/C1]Nh=KIOlnLQUKX@Y10QX44i +MicrosoftAppId= +MicrosoftAppPassword= diff --git a/libraries/botbuilder/tests/teams/link-unfurling/src/linkUnfurling.ts b/libraries/botbuilder/tests/teams/link-unfurling/src/linkUnfurling.ts index 69bc3b9fa0..c6952add1b 100644 --- a/libraries/botbuilder/tests/teams/link-unfurling/src/linkUnfurling.ts +++ b/libraries/botbuilder/tests/teams/link-unfurling/src/linkUnfurling.ts @@ -2,14 +2,15 @@ // Licensed under the MIT License. import { + AppBasedLinkQuery, MessagingExtensionResponse, MessagingExtensionResult, TeamsActivityHandler, - InvokeResponseTyped, CardFactory, ThumbnailCard, CardImage, - HeroCard } + HeroCard, + TurnContext } from 'botbuilder'; export class LinkUnfurlingBot extends TeamsActivityHandler { @@ -23,14 +24,15 @@ export class LinkUnfurlingBot extends TeamsActivityHandler { // 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. - this.onAppBasedLinkQuery(async (context, query, next) => { - const attachment = CardFactory.thumbnailCard('Thumbnail Card', query.url, ["https://raw.githubusercontent.com/microsoft/botframework-sdk/master/icon.png"]); + // "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 { + const attachment = CardFactory.thumbnailCard('Thumbnail Card', query.url, ["https://raw.githubusercontent.com/microsoft/botframework-sdk/master/icon.png"]); const result: MessagingExtensionResult = { attachmentLayout: 'list', @@ -42,14 +44,8 @@ export class LinkUnfurlingBot extends TeamsActivityHandler { composeExtension: result, } - const invoke_response: InvokeResponseTyped = { - status: 200, - body: response, - }; // For Invoke activities from Teams, we're currently not continuing the chain of handlers. // await next(); - return Promise.resolve(invoke_response); - - }); + return Promise.resolve(response); } } diff --git a/libraries/botbuilder/tests/teams/link-unfurling/teams-app-manifest/manifest.json b/libraries/botbuilder/tests/teams/link-unfurling/teams-app-manifest/manifest.json index 94a3498047..590276efa2 100644 --- a/libraries/botbuilder/tests/teams/link-unfurling/teams-app-manifest/manifest.json +++ b/libraries/botbuilder/tests/teams/link-unfurling/teams-app-manifest/manifest.json @@ -2,7 +2,7 @@ "$schema": "https://github.com/OfficeDev/microsoft-teams-app-schema/blob/preview/DevPreview/MicrosoftTeams.schema.json", "manifestVersion": "1.5", "version": "1.0", - "id": "cd59cf47-aca1-41e0-8441-387faee8331e", + "id": "<>", "packageName": "com.teams.sample.linkunfurling", "developer": { "name": "Link Unfurling1", @@ -25,13 +25,13 @@ "accentColor": "#FFFFFF", "bots": [ { - "botId": "cd59cf47-aca1-41e0-8441-387faee8331e", + "botId": "<>", "scopes": [ "personal", "team" ] } ], "composeExtensions": [ { - "botId": "cd59cf47-aca1-41e0-8441-387faee8331e", + "botId": "<>", "commands": [ { "id": "searchQuery", From 217eecb77531dc6c8edd989e5e2d1f16ce9d9551 Mon Sep 17 00:00:00 2001 From: Tien Suwandy Date: Tue, 15 Oct 2019 20:51:29 -0700 Subject: [PATCH 3/3] Addressed PR comments from stevengum --- .../tests/teams/link-unfurling/src/index.ts | 2 -- .../teams/link-unfurling/src/linkUnfurling.ts | 30 ++++++++----------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/libraries/botbuilder/tests/teams/link-unfurling/src/index.ts b/libraries/botbuilder/tests/teams/link-unfurling/src/index.ts index c2f4cdb4fc..e5a3ce3b29 100644 --- a/libraries/botbuilder/tests/teams/link-unfurling/src/index.ts +++ b/libraries/botbuilder/tests/teams/link-unfurling/src/index.ts @@ -30,8 +30,6 @@ const adapter = new BotFrameworkAdapter({ 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. diff --git a/libraries/botbuilder/tests/teams/link-unfurling/src/linkUnfurling.ts b/libraries/botbuilder/tests/teams/link-unfurling/src/linkUnfurling.ts index c6952add1b..add54d07cf 100644 --- a/libraries/botbuilder/tests/teams/link-unfurling/src/linkUnfurling.ts +++ b/libraries/botbuilder/tests/teams/link-unfurling/src/linkUnfurling.ts @@ -3,13 +3,10 @@ import { AppBasedLinkQuery, + CardFactory, MessagingExtensionResponse, MessagingExtensionResult, TeamsActivityHandler, - CardFactory, - ThumbnailCard, - CardImage, - HeroCard, TurnContext } from 'botbuilder'; @@ -20,7 +17,6 @@ export class LinkUnfurlingBot extends TeamsActivityHandler { // 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}'`); - await context.sendActivity(`Second response! '${context.activity.text}'`); // By calling next() you ensure that the next BotHandler is run. await next(); }); @@ -34,18 +30,16 @@ export class LinkUnfurlingBot extends TeamsActivityHandler { protected async onTeamsAppBasedLinkQuery(context: TurnContext, query: AppBasedLinkQuery): Promise { 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, - } - - // For Invoke activities from Teams, we're currently not continuing the chain of handlers. - // await next(); - return Promise.resolve(response); + const result: MessagingExtensionResult = { + attachmentLayout: 'list', + type: 'result', + attachments: [attachment], + text: 'test unfurl', + } + const response: MessagingExtensionResponse = { + composeExtension: result, + } + + return response; } }