Class DefaultWebhookPlugin
Default on-site webhook plugin. The plugin handles broadcasting the HTTP hooks to subscribing systems, and saving and storing the plugin info in the local database.
Inherited Members
Namespace: SuperOffice.CRM.Webhooks
Assembly: SoDataBase.BusinessLogic.dll
Syntax
[SystemWebhookPlugin("Default", 2147483647)]
public class DefaultWebhookPlugin : ISystemWebhookPlugin, ICustomWebhookPlugin, IDisposable
Constructors
DefaultWebhookPlugin(IWebhookTransmitter)
Default on-site webhook plugin. The plugin handles broadcasting the HTTP hooks to subscribing systems, and saving and storing the plugin info in the local database.
Declaration
public DefaultWebhookPlugin(IWebhookTransmitter webhookTransmitter)
Parameters
Type | Name | Description |
---|---|---|
IWebhookTransmitter | webhookTransmitter |
Fields
_webhookTransmitter
Default on-site webhook plugin. The plugin handles broadcasting the HTTP hooks to subscribing systems, and saving and storing the plugin info in the local database.
Declaration
protected readonly IWebhookTransmitter _webhookTransmitter
Field Value
Type | Description |
---|---|
IWebhookTransmitter |
Methods
AddToWebhookCountersAsync(int, int, int, int, string, CancellationToken)
Default on-site webhook plugin. The plugin handles broadcasting the HTTP hooks to subscribing systems, and saving and storing the plugin info in the local database.
Declaration
protected Task AddToWebhookCountersAsync(int webhookId, int numCalls, int numErrors, int numConsecutive, string message, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
int | webhookId | |
int | numCalls | |
int | numErrors | |
int | numConsecutive | |
string | message | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
DeleteWebhookAsync(int, CancellationToken)
Remove a given webhook from storage.
Declaration
public Task DeleteWebhookAsync(int id, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
int | id | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
Dispose()
Default on-site webhook plugin. The plugin handles broadcasting the HTTP hooks to subscribing systems, and saving and storing the plugin info in the local database.
Declaration
public void Dispose()
Dispose(bool)
Default on-site webhook plugin. The plugin handles broadcasting the HTTP hooks to subscribing systems, and saving and storing the plugin info in the local database.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing |
GetAllWebhooksAsync(string, string, string, WebhookState?, CancellationToken)
Return all the stored webhooks.
Declaration
public Task<IEnumerable<Webhook>> GetAllWebhooksAsync(string name = null, string eventName = null, string appToken = null, WebhookState? state = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | name | Optional name of webhook to filter on. |
string | eventName | Optional name of event to filter list of webhooks on. Default NULL for no filter. |
string | appToken | Optional appToken name to filter on. |
WebhookState? | state | Optional state to filter list of webhooks on. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<IEnumerable<Webhook>> | List of webhooks (that are listening to eventName) |
GetLastErrorAsync(int, CancellationToken)
Return most recent error message received from webhook target.
Declaration
public Task<string> GetLastErrorAsync(int id, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
int | id | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<string> | String containing most recent error message received from webhook target. |
GetWebhookAsync(int, CancellationToken)
Get a single webhook by id
Declaration
public Task<Webhook> GetWebhookAsync(int id, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
int | id | primary key for webhook |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<Webhook> | The given webhook, or NULL if not found |
NotifyAsync(Webhook, WebhookPayload, CancellationToken)
Send the event to a webhook, and mark failures/success status on the passed webhook objects. Called from the dispatcher on a background thread.
Declaration
public virtual Task<WebhookResponse> NotifyAsync(Webhook webhook, WebhookPayload eventInfo, CancellationToken cancellationToken)
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 |
Returns
Type | Description |
---|---|
Task<WebhookResponse> | Success/Failure information. NULL is taken as SUCCESS |
RecordResultAsync(Webhook, WebhookResponse, CancellationToken)
Default on-site webhook plugin. The plugin handles broadcasting the HTTP hooks to subscribing systems, and saving and storing the plugin info in the local database.
Declaration
public Task RecordResultAsync(Webhook webhook, WebhookResponse result, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
Webhook | webhook | |
WebhookResponse | result | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
SaveWebhookAsync(Webhook)
Store/Create a webhook.
Declaration
public Task<Webhook> SaveWebhookAsync(Webhook webhook)
Parameters
Type | Name | Description |
---|---|---|
Webhook | webhook | webhook to store. Create new hook if id=0 |
Returns
Type | Description |
---|---|
Task<Webhook> | Updated webhook, with primary key set. |
TestWebhookAsync(Webhook, CancellationToken)
Test invoke a webhook with a PING event to see if it works. Calls webhook with event "test" on entity "test".
Declaration
public Task<WebhookResponse> TestWebhookAsync(Webhook webhook, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Webhook | webhook | webhook definition |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<WebhookResponse> | True if the webhook invocation worked, False if we did not get 200 OK. NULL is treated as failure. |
UpdateWebhookStateAsync(int, WebhookState, CancellationToken)
Default on-site webhook plugin. The plugin handles broadcasting the HTTP hooks to subscribing systems, and saving and storing the plugin info in the local database.
Declaration
protected Task UpdateWebhookStateAsync(int webhookId, WebhookState webhookState, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
int | webhookId | |
WebhookState | webhookState | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |