Class WebhookTransmitter
Default implementation of IWebhookTransmitter
Implements
Inherited Members
Namespace: SuperOffice.CRM.Webhooks
Assembly: SoDataBase.BusinessLogic.dll
Syntax
public class WebhookTransmitter : IWebhookTransmitter
Remarks
Format a webhook request, send it to the target URL, and handle retries if the request fails.
Retries are handled by the IDelayedAsyncQueue<TItem> passed in the constructor.
Items on that queue are processed by the RetryWebhookProcessor, which is a
separate hosted service. That service will call the ProcessRetryAttemptAsync(IAsyncQueueProcessItemContext<DelayedItem<RetryWebhook>>, CancellationToken) in this class
to do the actual retry of the transmission.
This class also contains all the logic to obtain and configure a HttpClient instance,
which is used to send the webhook requests. HttpClient lifetime is a complicated mess,
see https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines#httpclient-lifetime
Constructors
WebhookTransmitter(IDelayedAsyncQueue<RetryWebhook>, ICustomProxyConfiguration, ILogger<WebhookTransmitter>)
Default implementation of IWebhookTransmitter
Declaration
public WebhookTransmitter(IDelayedAsyncQueue<RetryWebhook> retryList, ConfigFile.ICustomProxyConfiguration customProxyConfig, ILogger<WebhookTransmitter> logger)
Parameters
| Type | Name | Description |
|---|---|---|
| IDelayedAsyncQueue<RetryWebhook> | retryList | |
| ConfigFile.ICustomProxyConfiguration | customProxyConfig | |
| ILogger<WebhookTransmitter> | logger |
Remarks
Format a webhook request, send it to the target URL, and handle retries if the request fails.
Retries are handled by the IDelayedAsyncQueue<TItem> passed in the constructor.
Items on that queue are processed by the RetryWebhookProcessor, which is a
separate hosted service. That service will call the ProcessRetryAttemptAsync(IAsyncQueueProcessItemContext<DelayedItem<RetryWebhook>>, CancellationToken) in this class
to do the actual retry of the transmission.
This class also contains all the logic to obtain and configure a HttpClient instance,
which is used to send the webhook requests. HttpClient lifetime is a complicated mess,
see https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines#httpclient-lifetime
Methods
AddHeadersToWebHookRequest(Webhook, WebhookPayload, HttpRequestMessage, JObject, int, bool)
Default implementation of IWebhookTransmitter
Declaration
protected void AddHeadersToWebHookRequest(Webhook webhook, WebhookPayload eventInfo, HttpRequestMessage request, JObject body, int retryCount, bool isTest)
Parameters
| Type | Name | Description |
|---|---|---|
| Webhook | webhook | |
| WebhookPayload | eventInfo | |
| HttpRequestMessage | request | |
| JObject | body | |
| int | retryCount | |
| bool | isTest |
Remarks
Format a webhook request, send it to the target URL, and handle retries if the request fails.
Retries are handled by the IDelayedAsyncQueue<TItem> passed in the constructor.
Items on that queue are processed by the RetryWebhookProcessor, which is a
separate hosted service. That service will call the ProcessRetryAttemptAsync(IAsyncQueueProcessItemContext<DelayedItem<RetryWebhook>>, CancellationToken) in this class
to do the actual retry of the transmission.
This class also contains all the logic to obtain and configure a HttpClient instance,
which is used to send the webhook requests. HttpClient lifetime is a complicated mess,
see https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines#httpclient-lifetime
CallWebhookAsync(Webhook, WebhookPayload, CancellationToken, int, bool)
Broadcast the event to all subscribers, and mark failures/success status on the passed webhook objects.
Declaration
public Task<WebhookResponse> CallWebhookAsync(Webhook webhook, WebhookPayload eventInfo, CancellationToken cancellationToken, int maxRetries = 3, bool isTest = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Webhook | webhook | Inform the given webhook that the event has occurred. |
| WebhookPayload | eventInfo | Event name, unique id and details |
| CancellationToken | cancellationToken | |
| int | maxRetries | |
| bool | isTest |
Returns
| Type | Description |
|---|---|
| Task<WebhookResponse> | Success/Failure information. NULL is taken as SUCCESS |
Remarks
Format a webhook request, send it to the target URL, and handle retries if the request fails.
Retries are handled by the IDelayedAsyncQueue<TItem> passed in the constructor.
Items on that queue are processed by the RetryWebhookProcessor, which is a
separate hosted service. That service will call the ProcessRetryAttemptAsync(IAsyncQueueProcessItemContext<DelayedItem<RetryWebhook>>, CancellationToken) in this class
to do the actual retry of the transmission.
This class also contains all the logic to obtain and configure a HttpClient instance,
which is used to send the webhook requests. HttpClient lifetime is a complicated mess,
see https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines#httpclient-lifetime
CreateWebHookRequestBody(Webhook, WebhookPayload)
Default implementation of IWebhookTransmitter
Declaration
protected JObject CreateWebHookRequestBody(Webhook webhook, WebhookPayload payload)
Parameters
| Type | Name | Description |
|---|---|---|
| Webhook | webhook | |
| WebhookPayload | payload |
Returns
| Type | Description |
|---|---|
| JObject |
Remarks
Format a webhook request, send it to the target URL, and handle retries if the request fails.
Retries are handled by the IDelayedAsyncQueue<TItem> passed in the constructor.
Items on that queue are processed by the RetryWebhookProcessor, which is a
separate hosted service. That service will call the ProcessRetryAttemptAsync(IAsyncQueueProcessItemContext<DelayedItem<RetryWebhook>>, CancellationToken) in this class
to do the actual retry of the transmission.
This class also contains all the logic to obtain and configure a HttpClient instance,
which is used to send the webhook requests. HttpClient lifetime is a complicated mess,
see https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines#httpclient-lifetime
ProcessRetryAttemptAsync(IAsyncQueueProcessItemContext<DelayedItem<RetryWebhook>>, CancellationToken)
Process retry attempts, that has been added to a queue.
Declaration
public Task<WebhookResponse> ProcessRetryAttemptAsync(IAsyncQueueProcessItemContext<DelayedItem<RetryWebhook>> context, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| IAsyncQueueProcessItemContext<DelayedItem<RetryWebhook>> | context | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<WebhookResponse> |
Remarks
Format a webhook request, send it to the target URL, and handle retries if the request fails.
Retries are handled by the IDelayedAsyncQueue<TItem> passed in the constructor.
Items on that queue are processed by the RetryWebhookProcessor, which is a
separate hosted service. That service will call the ProcessRetryAttemptAsync(IAsyncQueueProcessItemContext<DelayedItem<RetryWebhook>>, CancellationToken) in this class
to do the actual retry of the transmission.
This class also contains all the logic to obtain and configure a HttpClient instance,
which is used to send the webhook requests. HttpClient lifetime is a complicated mess,
see https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines#httpclient-lifetime
RetryWebhookAsync(RetryWebhook, CancellationToken)
Default implementation of IWebhookTransmitter
Declaration
public Task<WebhookResponse> RetryWebhookAsync(RetryWebhook retry, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| RetryWebhook | retry | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<WebhookResponse> |
Remarks
Format a webhook request, send it to the target URL, and handle retries if the request fails.
Retries are handled by the IDelayedAsyncQueue<TItem> passed in the constructor.
Items on that queue are processed by the RetryWebhookProcessor, which is a
separate hosted service. That service will call the ProcessRetryAttemptAsync(IAsyncQueueProcessItemContext<DelayedItem<RetryWebhook>>, CancellationToken) in this class
to do the actual retry of the transmission.
This class also contains all the logic to obtain and configure a HttpClient instance,
which is used to send the webhook requests. HttpClient lifetime is a complicated mess,
see https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines#httpclient-lifetime
SendHttpRequestAsync(WebhookPayload, HttpRequestMessage, WebhookResponse, CancellationToken)
Default implementation of IWebhookTransmitter
Declaration
protected virtual Task SendHttpRequestAsync(WebhookPayload eventInfo, HttpRequestMessage request, WebhookResponse result, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| WebhookPayload | eventInfo | |
| HttpRequestMessage | request | |
| WebhookResponse | result | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
Remarks
Format a webhook request, send it to the target URL, and handle retries if the request fails.
Retries are handled by the IDelayedAsyncQueue<TItem> passed in the constructor.
Items on that queue are processed by the RetryWebhookProcessor, which is a
separate hosted service. That service will call the ProcessRetryAttemptAsync(IAsyncQueueProcessItemContext<DelayedItem<RetryWebhook>>, CancellationToken) in this class
to do the actual retry of the transmission.
This class also contains all the logic to obtain and configure a HttpClient instance,
which is used to send the webhook requests. HttpClient lifetime is a complicated mess,
see https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines#httpclient-lifetime
SendWebhookAsync(RetryWebhook, WebhookResponse, CancellationToken)
Default implementation of IWebhookTransmitter
Declaration
protected Task SendWebhookAsync(RetryWebhook retry, WebhookResponse result, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| RetryWebhook | retry | |
| WebhookResponse | result | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
Remarks
Format a webhook request, send it to the target URL, and handle retries if the request fails.
Retries are handled by the IDelayedAsyncQueue<TItem> passed in the constructor.
Items on that queue are processed by the RetryWebhookProcessor, which is a
separate hosted service. That service will call the ProcessRetryAttemptAsync(IAsyncQueueProcessItemContext<DelayedItem<RetryWebhook>>, CancellationToken) in this class
to do the actual retry of the transmission.
This class also contains all the logic to obtain and configure a HttpClient instance,
which is used to send the webhook requests. HttpClient lifetime is a complicated mess,
see https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines#httpclient-lifetime
ServerCertificateCustomValidationCallback(object, X509Certificate, X509Chain, SslPolicyErrors)
Verify SSL certificate is ok, deny bogus SSL certs
Declaration
protected static bool ServerCertificateCustomValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
Parameters
| Type | Name | Description |
|---|---|---|
| object | sender | |
| X509Certificate | certificate | |
| X509Chain | chain | |
| SslPolicyErrors | sslPolicyErrors |
Returns
| Type | Description |
|---|---|
| bool | True if SSL cert is ok |
Remarks
Format a webhook request, send it to the target URL, and handle retries if the request fails.
Retries are handled by the IDelayedAsyncQueue<TItem> passed in the constructor.
Items on that queue are processed by the RetryWebhookProcessor, which is a
separate hosted service. That service will call the ProcessRetryAttemptAsync(IAsyncQueueProcessItemContext<DelayedItem<RetryWebhook>>, CancellationToken) in this class
to do the actual retry of the transmission.
This class also contains all the logic to obtain and configure a HttpClient instance,
which is used to send the webhook requests. HttpClient lifetime is a complicated mess,
see https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines#httpclient-lifetime
SignWebHookRequest(Webhook, WebhookPayload, HttpRequestMessage, JObject)
Default implementation of IWebhookTransmitter
Declaration
protected void SignWebHookRequest(Webhook webhook, WebhookPayload eventInfo, HttpRequestMessage request, JObject body)
Parameters
| Type | Name | Description |
|---|---|---|
| Webhook | webhook | |
| WebhookPayload | eventInfo | |
| HttpRequestMessage | request | |
| JObject | body |
Remarks
Format a webhook request, send it to the target URL, and handle retries if the request fails.
Retries are handled by the IDelayedAsyncQueue<TItem> passed in the constructor.
Items on that queue are processed by the RetryWebhookProcessor, which is a
separate hosted service. That service will call the ProcessRetryAttemptAsync(IAsyncQueueProcessItemContext<DelayedItem<RetryWebhook>>, CancellationToken) in this class
to do the actual retry of the transmission.
This class also contains all the logic to obtain and configure a HttpClient instance,
which is used to send the webhook requests. HttpClient lifetime is a complicated mess,
see https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines#httpclient-lifetime