Module: Teleflow::Api::Events

Included in:
Client
Defined in:
lib/teleflow/api/events.rb

Overview

Module Teleflow::Api::Events provides an API for managing events in the Teleflow application.

This module includes methods for trigger, bulk trigger, broadcast and cancel events.

For more information on the Teleflow API(api-teleflow.khulnasoft.com/api#/Events), see docs.teleflow.khulnasoft.com/api/trigger-event/.

Instance Method Summary collapse

Instance Method Details

#broadcast_event(body) ⇒ Hash, number

Trigger a broadcast event to all existing subscribers, could be used to send announcements, etc. In the future could be used to trigger events to a subset of subscribers based on defined filters.

@bodyparams:

Parameters:

  • `name` (String)

    The trigger identifier associated for the template you wish to send. This identifier can be found on the template page.

  • `payload` (Hash)

    The payload object is used to pass additional custom information that could be used to render the template, or perform routing rules based on it. This data will also be available when fetching the notifications feed from the API to display certain parts of the UI

  • `overrides` (Hash(optional))

    This could be used to override provider specific configurations.

  • `transactionId` (String(optional))

    A unique identifier for this transaction, we will generated a UUID if not provided.

  • `actor` (Hash(optional))

    It is used to display the Avatar of the provided actor’s subscriber id or actor object. If a new actor object is provided, we will create a new subscriber in our system

Returns:

  • (Hash)
    • acknowledged [Boolean] - If trigger was acknowledged or not

    • status [String] - Status for trigger

    • error [Array(optional)] - In case of an error, this field will contain the error message

    • transactionId [String(optional)] - Transaction id for trigger

  • (number)

    status - The status code. Returns 201 if the event has been successfully broadcast to all existing subscribers.



72
73
74
# File 'lib/teleflow/api/events.rb', line 72

def broadcast_event(body)
  post("/events/trigger/broadcast", body: body)
end

#cancel_triggered_event(transaction_id) ⇒ number

Using a previously generated transactionId during the event trigger, will cancel any active or pending workflows. This is useful to cancel active digests, delays etc…

@pathparams:

Parameters:

  • `transactionId` (String)
    • transaction id of the event

Returns:

  • (number)

    status - The status code. Returns 200 if the event has been successfully cancelled.



83
84
85
# File 'lib/teleflow/api/events.rb', line 83

def cancel_triggered_event(transaction_id)
  delete("/events/trigger/#{transaction_id}")
end

#trigger_bulk_event(body) ⇒ Hash, number

Using this endpoint you can trigger multiple events at once, to avoid multiple calls to the API. The bulk API is limited to 100 events per request.

@bodyparams:

Parameters:

  • `events` (Array[event])

    @event : event structure @param ‘name` [String] The trigger identifier of the template you wish to send. This identifier can be found on the template page. @param `payload` [Hash] The payload object is used to pass additional custom information that could be used to render the template, or perform routing rules based on it. This data will also be available when fetching the notifications feed from the API to display certain parts of the UI. @param `overrides` [Hash(optional)] This could be used to override provider specific configurations. @param `to` [Hash] The recipients list of people who will receive the notification. @param `transactionId` [String(optional)] A unique identifier for this transaction, we will generated a UUID if not provided. @param `actor` [Hash(optional)] It is used to display the Avatar of the provided actor’s subscriber id or actor object. If a new actor object is provided, we will create a new subscriber in our system

Returns:

  • (Hash)
    • acknowledged [Boolean] - If trigger was acknowledged or not

    • status [String] - Status for trigger

    • error [Array(optional)] - In case of an error, this field will contain the error message

    • transactionId [String(optional)] - Transaction id for trigger

  • (number)

    status - The status code. Returns 201 if the event has been successfully triggered.



52
53
54
# File 'lib/teleflow/api/events.rb', line 52

def trigger_bulk_event(body)
  post("/events/trigger/bulk", body: body.to_json, headers: {'Content-Type': 'application/json'})
end

#trigger_event(body) ⇒ Hash, number

Trigger event is the main (and the only) way to send notification to subscribers. The trigger identifier is used to match the particular template associated with it. Additional information can be passed according the body interface below

@bodyparams:

Parameters:

  • `name` (String)

    The trigger identifier of the template you wish to send. This identifier can be found on the template page.

  • `payload` (Hash)

    The payload object is used to pass additional custom information that could be used to render the template, or perform routing rules based on it. This data will also be available when fetching the notifications feed from the API to display certain parts of the UI.

  • `overrides` (Hash(optional))

    This could be used to override provider specific configurations.

  • `to` (Hash)

    The recipients list of people who will receive the notification.

  • `transactionId` (String(optional))

    A unique identifier for this transaction, we will generated a UUID if not provided.

  • `actor` (Hash(optional))

    It is used to display the Avatar of the provided actor’s subscriber id or actor object. If a new actor object is provided, we will create a new subscriber in our system

Returns:

  • (Hash)
    • acknowledged [Boolean] - If trigger was acknowledged or not

    • status [String] - Status for trigger

    • error [Array(optional)] - In case of an error, this field will contain the error message

    • transactionId [String(optional)] - Transaction id for trigger

  • (number)

    status - The status code. Returns 201 if the event has been successfully triggered.



29
30
31
# File 'lib/teleflow/api/events.rb', line 29

def trigger_event(body)
  post("/events/trigger", body: body)
end