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.
Namespace: SuperOffice.CRM.Webhooks
Assembly: SoDataBase.dll
Syntax
[SystemWebhookPlugin("Default", 2147483647)]
public class DefaultWebhookPlugin : Object, ISystemWebhookPlugin, ICustomWebhookPlugin, IPlugin, IDisposable
Constructors
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.
Declaration
public DefaultWebhookPlugin()
Methods
AddHeadersToWebHookRequest(Webhook, WebhookPayload, HttpRequestMessage, JObject, Int32, Boolean)
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 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 | |
Int32 | retryCount | |
Boolean | isTest |
AddToWebhookCounters(Int32, Int32, Int32, Int32, String)
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 void AddToWebhookCounters(int webhookId, int numCalls, int numErrors, int numConsecutive, string message)
Parameters
Type | Name | Description |
---|---|---|
Int32 | webhookId | |
Int32 | numCalls | |
Int32 | numErrors | |
Int32 | numConsecutive | |
String | message |
CallWebhook(Webhook, WebhookPayload, Int32, Boolean)
Broadcast the event to all subscribers, and mark failures/success status on the passed webhook objects.
Declaration
protected WebhookResponse CallWebhook(Webhook webhook, WebhookPayload eventInfo, 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 |
Int32 | maxRetries | |
Boolean | isTest |
Returns
Type | Description |
---|---|
WebhookResponse | Success/Failure information. NULL is taken as SUCCESS |
CreateWebHookRequestBody(Webhook, WebhookPayload)
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 JObject CreateWebHookRequestBody(Webhook webhook, WebhookPayload payload)
Parameters
Type | Name | Description |
---|---|---|
Webhook | webhook | |
WebhookPayload | payload |
Returns
Type | Description |
---|---|
JObject |
DeleteWebhook(Int32)
Remove a given webhook from storage.
Declaration
public void DeleteWebhook(int id)
Parameters
Type | Name | Description |
---|---|---|
Int32 | id |
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(Boolean)
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 |
---|---|---|
Boolean | disposing |
GetAllWebhooks(String, String, String, Nullable<WebhookState>)
Return all the stored webhooks.
Declaration
public IEnumerable<Webhook> GetAllWebhooks(string name = null, string eventName = null, string appToken = null, Nullable<WebhookState> state = null)
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. |
Nullable<WebhookState> | state | Optional state to filter list of webhooks on. |
Returns
Type | Description |
---|---|
IEnumerable<Webhook> | List of webhooks (that are listening to eventName) |
GetLastError(Int32)
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 string GetLastError(int id)
Parameters
Type | Name | Description |
---|---|---|
Int32 | id |
Returns
Type | Description |
---|---|
String |
GetWebhook(Int32)
Get a single webhook by id
Declaration
public Webhook GetWebhook(int id)
Parameters
Type | Name | Description |
---|---|---|
Int32 | id | primary key for webhook |
Returns
Type | Description |
---|---|
Webhook | The given webhook, or NULL if not found |
Notify(Webhook, WebhookPayload)
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 WebhookResponse Notify(Webhook webhook, WebhookPayload eventInfo)
Parameters
Type | Name | Description |
---|---|---|
Webhook | webhook | Inform the given webhook that the event has occurred. |
WebhookPayload | eventInfo | Event name, unique id and details |
Returns
Type | Description |
---|---|
WebhookResponse | Success/Failure information. NULL is taken as SUCCESS |
RecordResult(Webhook, WebhookResponse)
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 void RecordResult(Webhook webhook, WebhookResponse result)
Parameters
Type | Name | Description |
---|---|---|
Webhook | webhook | |
WebhookResponse | result |
SaveWebhook(Webhook)
Store/Create a webhook.
Declaration
public Webhook SaveWebhook(Webhook webhook)
Parameters
Type | Name | Description |
---|---|---|
Webhook | webhook | webhook to store. Create new hook if id=0 |
Returns
Type | Description |
---|---|
Webhook | Updated webhook, with primary key set. |
SendHttpRequest(WebhookPayload, HttpRequestMessage, WebhookResponse)
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 SendHttpRequest(WebhookPayload eventInfo, HttpRequestMessage request, WebhookResponse result)
Parameters
Type | Name | Description |
---|---|---|
WebhookPayload | eventInfo | |
HttpRequestMessage | request | |
WebhookResponse | result |
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 |
---|---|
Boolean | True if SSL cert is ok |
SignWebHookRequest(Webhook, WebhookPayload, HttpRequestMessage, JObject)
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 void SignWebHookRequest(Webhook webhook, WebhookPayload eventInfo, HttpRequestMessage request, JObject body)
Parameters
Type | Name | Description |
---|---|---|
Webhook | webhook | |
WebhookPayload | eventInfo | |
HttpRequestMessage | request | |
JObject | body |
TestWebhook(Webhook)
Test invoke a webhook with a PING event to see if it works. Calls webhook with event "test" on entity "test".
Declaration
public WebhookResponse TestWebhook(Webhook webhook)
Parameters
Type | Name | Description |
---|---|---|
Webhook | webhook | webhook definition |
Returns
Type | Description |
---|---|
WebhookResponse | True if the webhook invocation worked, False if we did not get 200 OK. NULL is treated as failure. |
UpdateWebhookState(Int32, WebhookState)
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 void UpdateWebhookState(int webhookId, WebhookState webhookState)
Parameters
Type | Name | Description |
---|---|---|
Int32 | webhookId | |
WebhookState | webhookState |