Interface IWebhookManager
Interface implemented by the WebhookManager class.
Namespace: SuperOffice.CRM.Webhooks
Assembly: SoDataBase.dll
Syntax
public interface IWebhookManager
Methods
DeleteWebhookAsync(int, CancellationToken)
Interface implemented by the WebhookManager class.
Declaration
Task DeleteWebhookAsync(int id, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| int | id | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
GetAllWebhooksAsync(string, string, string, WebhookState?, CancellationToken)
Return all the stored webhooks.
Declaration
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, in state, with given name) |
GetLastErrorAsync(int, CancellationToken)
Interface implemented by the WebhookManager class.
Declaration
Task<string> GetLastErrorAsync(int webhookId, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| int | webhookId | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<string> |
GetWebhookAsync(int, CancellationToken)
Get a single webhook by id
Declaration
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 no found |
Notify(ChangeType, int, string, IDictionary<string, object>, int, IDictionary<string, object>)
Asynchronously inform all interested plugins that an event has occurred. In other words, we don't block on calls here. This method will return before the webhooks finish processing.
Declaration
void Notify(ChangeType changeType, int primaryKey, string entityName, IDictionary<string, object> changes, int associateId, IDictionary<string, object> fieldValues)
Parameters
| Type | Name | Description |
|---|---|---|
| ChangeType | changeType | Created/Changed/Deleted/softDeleted |
| int | primaryKey | id |
| string | entityName | "contact", "sale", etc |
| IDictionary<string, object> | changes | Dictionary of changed fields "name", "country_id" mapped to the new values. |
| int | associateId | User id who triggered event. |
| IDictionary<string, object> | fieldValues |
NotifyWebhooksAsync(IEnumerable<Webhook>, WebhookPayload, CancellationToken)
Call out to the actual webhooks
Declaration
Task NotifyWebhooksAsync(IEnumerable<Webhook> webhooks, WebhookPayload eventInfo, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<Webhook> | webhooks | |
| WebhookPayload | eventInfo | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
RecordResult(Webhook, WebhookResponse, CancellationToken)
Record the result of a webhook call in memoory or on database. May change state of webhook if too many errors or permanent failure.
Declaration
Task RecordResult(Webhook hook, WebhookResponse result, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| Webhook | hook | |
| WebhookResponse | result | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
SaveWebhookAsync(Webhook)
Store/Create a webhook.
Declaration
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. |
SignalEvent(string, int, string, IDictionary<string, object>, int)
Asynchronously inform all interested webhooks that an event has occurred. In other words, we don't block on calls here. This method will return before the webhooks finish processing.
Declaration
void SignalEvent(string eventName, int primaryKey, string entityName, IDictionary<string, object> changes, int associateId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | eventName | |
| int | primaryKey | id |
| string | entityName | "contact", "sale", etc |
| IDictionary<string, object> | changes | Dictionary of changed fields "name", "country_id" mapped to the new values. |
| int | associateId | User id who triggered event. |
TestWebhookAsync(Webhook, CancellationToken)
Test invoke a webhook with a PING event to see if it works.
Declaration
Task<WebhookResponse> TestWebhookAsync(Webhook webhook, CancellationToken cancellationToken = default)
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. |
WaitForWebhooksToCompleteAsync(CancellationToken)
Wait for all webhooks currently being processed or in the queue to be completed. Primarely used by tests verifying that webhooks are called.
Declaration
Task WaitForWebhooksToCompleteAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |