public static IServiceCollection AddViberBotApi(this IServiceCollection services, Action <ViberBotConfiguration> action) { ViberBotConfiguration conf = new ViberBotConfiguration(); action.Invoke(conf); var bot = ViberClient.RegisterViberApi(conf); bot.SetWebHookAsync(new ViberWebHook.WebHookRequest(conf.Webhook)); services.AddSingleton(bot); return(services); }
public static IViberBotApi RegisterViberApi(ViberBotConfiguration conf) { var client = new HttpClient(); client.BaseAddress = new Uri($"https://chatapi.viber.com/pa/"); client.DefaultRequestHeaders.Add("X-Viber-Auth-Token", conf.Token); return(RestService.For <IViberBotApi>(client, new RefitSettings() { CollectionFormat = CollectionFormat.Multi, ContentSerializer = new NewtonsoftJsonContentSerializer(new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }) })); }