/// <summary> /// Builds an ISender using the given auth key for the given protocol /// </summary> /// <param name="authKey"></param> /// <param name="protocol"></param> public ISender BuildBlipClient(string authKey, BlipProtocol protocol, List <Document> documents = null) { switch (protocol) { case BlipProtocol.Http: return(BuildHttpClient(authKey, documents)); case BlipProtocol.Tcp: default: return(BuildTcpClient(authKey)); } }
/// <summary> /// Builds an ISender using the given auth key for the given protocol /// </summary> /// <param name="authKey"></param> /// <param name="protocol"></param> /// <param name="documents"></param> public ISender BuildBlipClient(string authKey, BlipProtocol protocol = BlipProtocol.Tcp, List <Document> documents = null) { authKey = FixAuthKey(authKey); var envelopeSerializer = CreateEnvelopeSerializer(documents); switch (protocol) { case BlipProtocol.Http: return(BuildHttpClient(authKey, envelopeSerializer)); default: return(BuildTcpClient(authKey, envelopeSerializer)); } }
/// <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); }
/// <summary> /// Creates a ThreadService instance using a given authKey. /// </summary> /// <param name="authKey">Bot authorization key</param> /// <param name="blipProtocol">Protocol to be used</param> public ThreadService(string authKey, BlipProtocol blipProtocol = BlipProtocol.Tcp) { var factory = new BlipClientFactory(); _sender = factory.BuildBlipClient(authKey, blipProtocol); }
/// <summary> /// Updates the ServiceCollection with any custom documents and BLiP's extensions /// </summary> /// <param name="services"></param> /// <param name="authKey"></param> /// <param name="documentList"></param> /// <param name="protocol">Defaults to Http to avoid breaking changes</param> /// <param name="domain">Domain of request in blip. Default is 'msging.net'</param> public static IServiceCollection DefaultRegister(this IServiceCollection services, string authKey, List <Document> documentList = null, BlipProtocol protocol = BlipProtocol.Http, string domain = null) { return(new BlipClientFactory(domain).BuildServiceCollection(authKey, protocol, documentList, services)); }
/// <summary> /// Creates a BroadcastService instance using a given authKey. /// </summary> /// <param name="authKey">Bot authorization key</param> /// <param name="protocol">Protocol to be used</param> public BroadcastService(string authKey, BlipProtocol protocol = BlipProtocol.Tcp) { var factory = new BlipClientFactory(); _sender = factory.BuildBlipClient(authKey, protocol); }