public ContextBaseTests() { var documentTypeResolver = new DocumentTypeResolver().WithMessagingDocuments(); ArtificialIntelligenceExtension = Substitute.For <IArtificialIntelligenceExtension>(); ContactExtension = Substitute.For <IContactExtension>(); TunnelExtension = Substitute.For <ITunnelExtension>(); Logger = Substitute.For <ILogger>(); Configuration = Substitute.For <IConfiguration>(); CacheOwnerCallerContactMap = new CacheOwnerCallerContactMap(); Sender = Substitute.For <ISender>(); Flow = new Flow() { Id = "0", Configuration = new Dictionary <string, string>() }; User = "******"; Application = "*****@*****.**"; Input = new LazyInput( new Message() { From = User.ToNode(), To = Application.ToNode(), Content = new PlainText() { Text = "Hello world!" } }, Flow.BuilderConfiguration, new DocumentSerializer(documentTypeResolver), new EnvelopeSerializer(documentTypeResolver), ArtificialIntelligenceExtension, CancellationToken); Configuration.ContactCacheExpiration.Returns(TimeSpan.FromMinutes(5)); }
/// <summary> /// Creates or updates a Service Collection to include BLiP's extensions and any custom Documents /// </summary> /// <param name="authKey"></param> /// <param name="documents"></param> /// <param name="serviceCollection"></param> /// <returns></returns> public IServiceCollection BuildServiceCollection(string authKey, List <Document> documents = null, IServiceCollection serviceCollection = null) { if (serviceCollection == null) { serviceCollection = new ServiceCollection(); } var documentResolver = new DocumentTypeResolver(); documentResolver.WithBlipDocuments(); if (documents != null) { foreach (Document d in documents) { documentResolver.RegisterDocument(d.GetType()); } } var envelopeSerializer = new EnvelopeSerializer(documentResolver); var client = new RestClient("https://msging.net/") { JsonSerializerSettings = envelopeSerializer.Settings }.For <IBlipHttpClient>(); client.Authorization = new AuthenticationHeaderValue("Key", authKey); var sender = new BlipHttpClient(client); serviceCollection.AddSingleton <ISender>(sender); serviceCollection.RegisterBlipExtensions(); return(serviceCollection); }
public SendMessageFromHttpActionTests() { Sender = Substitute.For <ISender>(); HttpClient = Substitute.For <IHttpClient>(); DocumentTypeResolver = new DocumentTypeResolver().WithBlipDocuments(); DocumentSerializer = new DocumentSerializer(DocumentTypeResolver); Context.Input.Returns(Input); }
public HttpSender(string authorizationKey, HttpClient httpClient) { authorizationKey = authorizationKey.Replace(AuthenticationPrefix, string.Empty); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AuthenticationPrefix.Trim(), authorizationKey); var documentResolver = new DocumentTypeResolver().WithBlipDocuments(); _envelopeSerializer = new EnvelopeSerializer(documentResolver); _httpClient = httpClient; }
private static IDocumentTypeResolver RegisterBlipTypes() { IDocumentTypeResolver typeResolver = new DocumentTypeResolver(); typeResolver.RegisterDocument <AnalysisResponse>(); typeResolver.RegisterDocument <Intention>(); typeResolver.RegisterDocument <Answer>(); typeResolver.RegisterDocument <Question>(); typeResolver.RegisterDocument <Entity>(); typeResolver.RegisterDocument <CallerResource>(); return(typeResolver); }
private EnvelopeSerializer CreateEnvelopeSerializer(List <Document> documents = null) { var documentResolver = new DocumentTypeResolver(); documentResolver.WithBlipDocuments(); documents?.ForEach(d => documentResolver.RegisterDocument(d.GetType())); var envelopeSerializer = new EnvelopeSerializer(documentResolver); return(envelopeSerializer); }
private static Container RegisterExternal(this Container container) { container.RegisterSingleton <IDocumentTypeResolver>(() => { var documentTypeResolver = new DocumentTypeResolver().WithBlipDocuments(); documentTypeResolver.RegisterDocument <InputExpiration>(); return(documentTypeResolver); }); container.RegisterSingleton <IEnvelopeSerializer, EnvelopeSerializer>(); container.RegisterSingleton <IDocumentSerializer, DocumentSerializer>(); container.RegisterSingleton <ILogger>(() => LoggerProvider.Logger); return(container); }
/// <summary> /// Builds an ISender using the given auth key /// </summary> /// <param name="authKey"></param> /// <returns></returns> public ISender BuildBlipHttpClient(string authKey) { if (authKey.StartsWith("Key ")) { authKey = authKey.Replace("Key ", ""); } var documentResolver = new DocumentTypeResolver(); documentResolver.WithBlipDocuments(); var envelopeSerializer = new EnvelopeSerializer(documentResolver); var client = new RestClient("https://msging.net/") { JsonSerializerSettings = envelopeSerializer.Settings }.For <IBlipHttpClient>(); client.Authorization = new AuthenticationHeaderValue("Key", authKey); return(new BlipHttpClient(client)); }
public ContextBaseTests() { var documentTypeResolver = new DocumentTypeResolver().WithMessagingDocuments(); ArtificialIntelligenceExtension = Substitute.For <IArtificialIntelligenceExtension>(); ContactExtension = Substitute.For <IContactExtension>(); HelpDeskExtension = Substitute.For <IHelpDeskExtension>(); TunnelExtension = Substitute.For <ITunnelExtension>(); Logger = Substitute.For <ILogger>(); Configuration = Substitute.For <IConfiguration>(); Sender = Substitute.For <ISender>(); Flow = new Flow() { Id = "0", Configuration = new Dictionary <string, string>() }; User = "******"; Application = new Application() { Identifier = "application", Domain = "msging.net", Instance = "default" }; Input = new LazyInput( new Message() { From = User.ToNode(), To = ApplicationIdentity.ToNode(), Content = new PlainText() { Text = "Hello world!" } }, User, Flow.BuilderConfiguration, new DocumentSerializer(documentTypeResolver), new EnvelopeSerializer(documentTypeResolver), ArtificialIntelligenceExtension, CancellationToken); }
/// <summary> /// Creates or updates a Service Collection to include BLiP's extensions and any custom Documents, including an <c>ISender</c> /// </summary> /// <param name="authKey"></param> /// <param name="protocol"></param> /// <param name="documents"></param> /// <param name="serviceCollection"></param> public IServiceCollection BuildServiceCollection(string authKey, BlipProtocol protocol, List <Document> documents = null, IServiceCollection serviceCollection = null) { serviceCollection = serviceCollection ?? new ServiceCollection(); var documentResolver = new DocumentTypeResolver(); documentResolver.WithBlipDocuments(); documents?.ForEach(d => documentResolver.RegisterDocument(d.GetType())); var envelopeSerializer = new EnvelopeSerializer(documentResolver); serviceCollection.AddSingleton <IEnvelopeSerializer>(envelopeSerializer); var sender = BuildBlipClient(authKey, protocol); serviceCollection.AddSingleton(sender); serviceCollection.RegisterBlipExtensions(); return(serviceCollection); }
private ISender BuildHttpClient(string authKey, List <Document> documents = null) { if (authKey.StartsWith(KEY_PREFIX)) { authKey = authKey.Replace(KEY_PREFIX, string.Empty).Trim(); } var documentResolver = new DocumentTypeResolver(); documentResolver.WithBlipDocuments(); documents?.ForEach(d => documentResolver.RegisterDocument(d.GetType())); var envelopeSerializer = new EnvelopeSerializer(documentResolver); var client = new RestClient(MSGING_BASE_URL) { JsonSerializerSettings = envelopeSerializer.Settings }.For <IBlipHttpClient>(); client.Authorization = new AuthenticationHeaderValue(KEY_PREFIX, authKey); return(new BlipHttpClient(client)); }
public void ConfigureServices(IServiceCollection services) { // Insert AppSettings var appSettings = Configuration.Get <AppSettings>(); services.AddSingleton(appSettings); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddCors(); var documentResolver = new DocumentTypeResolver().WithBlipDocuments(); services.AddSingleton <IEnvelopeSerializer>(new EnvelopeSerializer(documentResolver)); #region Dependency injection // Serilog var loggerConfiguration = new LoggerConfiguration() .ReadFrom.Configuration(Configuration) .Enrich.WithMachineName() .Enrich.WithProperty("Application", "Take.Api.Desk") .Enrich.WithExceptionDetails() .CreateLogger(); services.AddSingleton <ILogger>(loggerConfiguration); services.AddHostedService <CheckQueueStatusBll>(); // Initialize Blip CLients var container = new Container(); foreach (var cfg in appSettings.BotConfigurations.Bots) { var blipClient = new BlipClientBuilder() .UsingHostName("msging.net") .UsingPort(55321) .UsingAccessKey(cfg.BotId, cfg.BotAccessKey) .UsingRoutingRule(RoutingRule.Instance) .UsingInstance(cfg.BotId) .WithChannelCount(1) .Build(); services.AddBlipClientToContainer(container, blipClient, cfg.BotId); } services.AddSingleton <IContainer>(container); services.AddMvc().AddJsonOptions(options => { foreach (var settingsConverter in JsonNetSerializer.Settings.Converters) { options.SerializerSettings.Converters.Add(settingsConverter); } }); // Injections Layer services.AddInjectionsBll(); #endregion services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Take desk", Version = "v1", Description = "Api" }); }); }
public SendRawMessageActionTests() { Sender = Substitute.For <ISender>(); DocumentTypeResolver = new DocumentTypeResolver().WithBlipDocuments(); DocumentSerializer = new DocumentSerializer(DocumentTypeResolver); }