forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdapterFactory.cs
More file actions
39 lines (33 loc) · 1.4 KB
/
Copy pathAdapterFactory.cs
File metadata and controls
39 lines (33 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Linq;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration;
using Microsoft.Bot.Configuration;
using Microsoft.Bot.Connector.Authentication;
namespace Microsoft.BotBuilderSamples
{
/// <summary>
/// A factory for the adapters we will be using, common code across each of the controllers.
/// </summary>
public static class AdapterFactory
{
public static IAdapterIntegration Create(BotConfiguration botConfig, string name)
{
var endpointName = $"{name} development";
var service = botConfig.Services.Where(s => s.Type == "endpoint" && s.Name == endpointName).FirstOrDefault();
if (!(service is EndpointService endpointService))
{
throw new InvalidOperationException($"The .bot file does not contain an endpoint with name '{name}'.");
}
var credentialProvider = new SimpleCredentialProvider(endpointService.AppId, endpointService.AppPassword);
var adapter = new BotFrameworkAdapter(credentialProvider);
adapter.OnTurnError = async (context, exception) =>
{
await context.SendActivityAsync($"Sorry, it looks like something went wrong in {name}.");
};
return adapter;
}
}
}