Exemple #1
0
 public TokensController(ILogger <TokensController> logger, IOptions <InDirectLineSettings> opt, DirectLineHelper helper, IDirectLineConnectionManager connectionManager, TokenBuilder tokenBuilder)
 {
     this._logger               = logger;
     this._helper               = helper;
     this._connectionManager    = connectionManager;
     this._tokenBuilder         = tokenBuilder;
     this._inDirectlineSettings = opt.Value;
 }
Exemple #2
0
 public DirectLineController(ILogger <DirectLineController> logger, IOptions <InDirectLineSettings> opt, DirectLineHelper helper, IDirectLineConnectionManager connectionManager, TokenBuilder tokenBuilder, IWebHostEnvironment env)
 {
     this._logger            = logger;
     this._helper            = helper;
     this._connectionManager = connectionManager;
     this._tokenBuilder      = tokenBuilder;
     this._env = env;
     this._inDirectlineSettings = opt.Value;
 }
        public WeiXinController(WeixinHelper helper, ILogger <WeiXinController> logger, IWeixinUserConversationStore ucstore, InDirectLineClient directLineClient, IOptions <InDirectLineSettings> opts)
        {
            this._helper   = helper;
            this._logger   = logger;
            this._ucstore  = ucstore;
            this._settings = opts.Value;

            this._directLineClient = directLineClient;
        }
Exemple #4
0
        public static IServiceCollection AddInDirectLine(this IServiceCollection services, InDirectLineSettings directlineOpts)
        {
            services.Configure <InDirectLineSettings>(opt => {
                foreach (var pi in opt.GetType().GetProperties())
                {
                    var propValue = pi.GetValue(directlineOpts);
                    pi.SetValue(opt, propValue);
                }
            });

            services.AddHttpClient();
            services.AddHttpContextAccessor();
            services.AddSingleton <IConversationHistoryStore, InMemoryConversationHistoryStore>();
            services.AddSingleton <IDirectLineConnection, WebSocketDirectLineConnection>();
            services.AddSingleton <IDirectLineConnectionManager, DirectLineConnectionManager>();
            services.AddSingleton <TokenBuilder>();
            services.AddScoped <ChannelServiceHandler, InDirectLineConversationHandler>();
            services.AddAuthorization(opt => {
                opt.AddPolicy("MatchConversation", pb => pb.Requirements.Add(new MatchConversationAuthzRequirement()));
            });
            services.AddHttpClient <InDirectLineClient>();

            var botEndPointUri = UtilsEx.GetOrigin(directlineOpts.BotEndpoint);

            services.AddSingleton <IAuthorizationHandler, MatchConversationAuthzHandler>();
            services.AddCors(options =>
            {
                options.AddPolicy(
                    InDirectLineDefaults.CorsPolicyNames,
                    builder => {
                    builder.WithOrigins(botEndPointUri);
                    builder.AllowAnyOrigin();
                    builder.AllowAnyHeader();
                    builder.AllowAnyMethod();
                }
                    );
            });
            services.AddScoped <WebSocketConnectionMiddleware>();
            return(services.AddScoped <DirectLineHelper>());
        }