public MessengerBot(string pageToken) { isWebhookEnabled = false; PageToken = pageToken; profileClient = new ProfileApiClient(pageToken); sendClient = new SendApiClient(pageToken); broadcastClient = new BroadcastApiClient(pageToken); }
public MessengerBot(int webhookPort, string appSecret, string pageToken, string verifyToken, LogLevel logLevel = DefaultLogLevel) : base(webhookPort, appSecret, verifyToken, logLevel) { isWebhookEnabled = true; PageToken = pageToken; profileClient = new ProfileApiClient(pageToken); sendClient = new SendApiClient(pageToken); broadcastClient = new BroadcastApiClient(pageToken); }
public async void ShouldSendRequestToFacebookCorrectly() { var factory = SetupHttpClientFactory(HttpStatusCode.OK, "{\"recipient_id\":\"sample-subscriber\",\"message_id\":\"sample-message-id\"}", "{\"messaging_type\":\"RESPONSE\",\"recipient\":{\"id\":\"sample-subscriber\"},\"message\":{\"text\":\"hello, world!\"}}" ); var request = new SendRequest("sample-subscriber", new Message("hello, world!")); var apiClient = new SendApiClient(factory, MockBuilder.BuildFakeConfiguration(), MockBuilder.BuildFakeLogger <SendApiClient>()); await apiClient.Send(request); }
public async Task ShouldMakeApiCallHonoringCustomConfigurations() { _http.RespondWithJson(_fixture.Create <SendMessageResponse>()); var service = new SendApiClient(_accessKey, config => { config.ApiVersion = "v3.4"; config.Timeout = TimeSpan.FromMinutes(2); }); await service.SendTextMessageAsync("123", "hello!"); _http .ShouldHaveCalled("*/v3.4/*") .With(call => call.FlurlRequest.Settings.Timeout == TimeSpan.FromMinutes(2) ); }
public async void ShouldHandleErrorWhileSendingRequestToFacebookCorrectly() { var factory = SetupHttpClientFactory(HttpStatusCode.BadRequest, "{\"error\":{\"message\":\"Invalid OAuth access token.\",\"type\":\"OAuthException\",\"code\":190,\"error_subcode\":1234567,\"fbtrace_id\":\"traceid\"}}", "{\"messaging_type\":\"RESPONSE\",\"recipient\":{\"id\":\"sample-subscriber\"},\"message\":{\"text\":\"hello, world!\"}}" ); var request = new SendRequest("sample-subscriber", new Message("hello, world!")); var apiClient = new SendApiClient(factory, MockBuilder.BuildFakeConfiguration(), MockBuilder.BuildFakeLogger <SendApiClient>()); try { await apiClient.Send(request); } catch (MessageSendingException exception) { exception.Message.Should() .BeEquivalentTo( "An exception was thrown while sending a message: Facebook Messenger GraphQL Endpoint returned non-success HTTP Status Code" ); } }
public void Intitialize() { client = new SendApiClient(PageToken); }
public void Setup() { _http = new HttpTest(); _accessKey = _fixture.Create <string>(); _apiClient = new SendApiClient(_accessKey); }