Skip to content
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

Msg-Ext Search SSO Config TTK Fixes #1168

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions samples/msgext-search-sso-config/nodejs/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"portOccupancy" // Validate available ports to ensure those debug ones are not occupied.
],
"portOccupancy": [
3978, // app service port
9239 // app inspector port for Node.js debugger
3978 // app service port
]
}
},
Expand Down Expand Up @@ -97,7 +96,7 @@
"background": {
"activeOnStart": true,
"beginsPattern": "[nodemon] starting",
"endsPattern": "restify listening to|Bot/ME service listening at|[nodemon] app crashed"
"endsPattern": "Bot started, restify listening to http://"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"${{BOT_DOMAIN}}"
],
"webApplicationInfo": {
"id": "${{AAD_APP_CLIENT_ID}}",
"id": "${{BOT_ID}}",
"resource": "api://botid-${{BOT_ID}}"
}
}
53 changes: 36 additions & 17 deletions samples/msgext-search-sso-config/nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ const {
CloudAdapter,
ConfigurationServiceClientCredentialFactory,
ConfigurationBotFrameworkAuthentication,
UserState,
UserState,
MemoryStorage,
BotFrameworkAdapter
} = require("botbuilder");
const { TeamsMessagingExtensionsSearchAuthConfigBot } = require('./bots/teamsMessagingExtensionsSearchAuthConfigBot');

Expand All @@ -36,28 +37,37 @@ const botFrameworkAuthentication = new ConfigurationBotFrameworkAuthentication(
credentialsFactory
);

const adapter = new CloudAdapter(botFrameworkAuthentication);
// Create adapter.
// See https://aka.ms/about-bot-adapter to learn more about adapters.
// cloud adapter
const _cloudAdapter = new CloudAdapter(botFrameworkAuthentication);

adapter.onTurnError = async (context, error) => {
// bot framework adapter
const _botFrameworkAdapter = new BotFrameworkAdapter({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword
});

_cloudAdapter.onTurnError = async (context, error) => {
// This check writes out errors to console log .vs. app insights.
// NOTE: In production environment, you should consider logging this to Azure
// application insights. See https://aka.ms/bottelemetry for telemetry
// configuration instructions.
console.error(`\n [onTurnError] unhandled error: ${error}`);

// Send a trace activity, which will be displayed in Bot Framework Emulator
await context.sendTraceActivity(
'OnTurnError Trace',
`${ error }`,
'https://www.botframework.com/schemas/error',
'TurnError'
);
await context.sendTraceActivity(
'OnTurnError Trace',
`${error}`,
'https://www.botframework.com/schemas/error',
'TurnError'
);

// Uncomment below commented line for local debugging.
// await context.sendActivity(`Sorry, it looks like something went wrong. Exception Caught: ${error}`);
// Uncomment below commented line for local debugging.
// await context.sendActivity(`Sorry, it looks like something went wrong. Exception Caught: ${error}`);

// Note: Since this Messaging Extension does not have the messageTeamMembers permission
// in the manifest, the bot will not be allowed to message users.
// Note: Since this Messaging Extension does not have the messageTeamMembers permission
// in the manifest, the bot will not be allowed to message users.

};

Expand All @@ -82,12 +92,21 @@ server.listen(process.env.port || process.env.PORT || 3978, function () {

// Listen for incoming requests.
server.post("/api/messages", async (req, res) => {
await adapter.process(req, res, async (context) => {
await bot.run(context);
});
// For signout command BotFrameworkAdapter is supported
if (req.body.value.commandId == 'SignOutCommand') {
await _botFrameworkAdapter.processActivity(req, res, async (context) => {
await bot.run(context);
});
}
else {
// If not Signout Command CloudAdapter will get hit;
await _cloudAdapter.process(req, res, async (context) => {
await bot.run(context);
});
}
});

// Serve up static files in the public directory (namely: searchSettings.html)
server.get('/public/*', restify.plugins.serveStatic({
directory: __dirname
directory: __dirname
}));