# Automating Business Processes & Funnels via Triggers

Trigger executes a set of operations, i.e. operations via external and internal API calls, API based notifications and messaging.

Triggers are activated by changes in:&#x20;

* [Objects](https://mobsted-2.gitbook.io/knowledge-base/references/intro-placeholder/objects)
* [Events](https://mobsted-2.gitbook.io/knowledge-base/references/intro-placeholder/events)
* [Statuses](https://mobsted-2.gitbook.io/knowledge-base/basics/introduction/broken-reference)

Triggers use [Filters](https://kb.mobsted.com/article/1iu48fq9db-filter-any-backend-data) to track data linked to the triggered operations. Currently, Mobsted platform supports triggers ran in automatic mode on new records. The trigger runs immidiately when a new filtered record appears.

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

#### CREATE YOUR FIRST TRIGGER

In this example the trigger will send the notification message to app user each time **Submit** button is clicked.

How this works:

1. Each time the button is clicked, an event with appropriate data is created ("*Send Message*" event)
2. Each time a new "*Send Message*" event is created, the appropriate filter detects those changes and notifies the attached trigger
3. Trigger executes attached notification operation (sends notification message).

Steps to take:

1. ADD SENDING MESSAGE API METHOD
2. ADD API BASED SENDING MESSAGE OPERATION
3. CREATE FILTER FOR BUTTON CLICK EVENTS
4. CREATE SENDING TRIGGER BASED ON BUTTON CLICK EVENTS FILTER
5. CHECK THE RESULT

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

#### ADD SENDING MESSAGE API METHOD

1. Navigate to **MY PROFILE** section in the top right corner![](https://storage.googleapis.com/helpdocs-assets/jyme83anlw/articles/6vuz0emhjg/1557735264977/image.png)
2. Go to **Keys** tab and copy **Primary** and **Secondary Key** to your favorite note app
3. Navigate to **Providers** section on the left hand side menu and click **Add API Provider**
4. Fill in:
   * &#x20;**Name**: *Mobsted*
   * **Base URL**: *https\://**\*yourTenantName\***.mobsted.com*
5. Click **Save** **API Provider** and then click **Create New API Provider Method**
6. Name the fields:
   * **Api Provider Method Name**: *send garant*
   * **Method**: *POST*
   * **Endpoint URL**: */api/v8/object/sendmessage*
   * **Consumes Type**: *application/json*
   * **Produces Type**: *application/json*
7. Click **Add parameters** at the bottom of the pop up and fill in the fields:
   * **Name**: *ApplicationId*
   * **In**: *formData*
   * **Type**: *String*
   * **Description**: *Application ID*
   * Check the box **Required**
   * Click **Save Parameter**
8. Click **Add parameters** again and fill in the fields:
   * **Name**: *message*
   * **In**: *formData*
   * **Type**: *String*
   * **Description**: *Message*
   * Check the box **Required**
   * Click **Save Parameter**
9. Click **Add parameters** again and fill in the fields:
   * **Name**: *email*
   * **In**: *formData*
   * **Type**: *String*
   * **Description**: *Object email*
   * Check the box **Required**
   * Click **Save Parameter**
10. Click **Save API Provider Method**
11. Click **Close**

<div align="left"><img src="https://877328951-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlgISQGimMcecefzSf2%2F-LotSPZs_al-9BYOV5cX%2F-LotSXBluReNjShCFjV8%2Ftrr.png?alt=media&#x26;token=d2a465f2-3538-45c9-b76b-eb72610300d7" alt=""></div>

&#x20;  13\. Go to **API KEYS** tab and click **Create New API Key**

&#x20;  14\. On **API Key - Create** page fill in the fields:

* **Api Key Name**: *Mobsted Key*
* **Method**: *Basic*

&#x20;   1&#x35;**. Key1 and Key2**: copy paste the keys you've copied on step **2**   &#x20;

{% hint style="info" %}
**Note:** if you generate new Mobsted API keys, make sure you have updated the keys in already exsisting operations with Mobsted provider.&#x20;
{% endhint %}

&#x20;  16\.  Click **Save** **API Key** and then **Close**.

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

#### ADD API BASED SENDING MESSAGE OPERATION

1. Click **Operations** on the left hand side menu
2. Click **Add Operation**
3. Open **Mobsted** dropdown on the left, select **send garant** method created on the previous step
4. Fill in the field: **Operation Name**: *Send Message*
5. In **EXECUTION** section fill in the parameters:

   1. **API Key**: *Mobsted Key*
   2. **applicationId**: *1* or use [Hashtag](https://mobsted-2.gitbook.io/knowledge-base/references/intro-placeholder/hashtags): *#Application:id#*
   3. **message:** *Hello*
   4. **email:** *#Object:Email#*

   ![](https://877328951-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlgISQGimMcecefzSf2%2F-LotSPZs_al-9BYOV5cX%2F-LotSm-bHZy68Sd_BCUT%2FTrtrg.png?alt=media\&token=172c3f7f-f9fb-447a-b394-b553a06218ac)
6. Click **Save Operation** and **Close**.

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

#### CREATE FILTER FOR BUTTON CLICK EVENTS

1. Open **Demo App**
2. Go to **Backend** on the top menu
3. Click **Add Filter** and then **Create New Filter**
4. **Name** the filter *Send Message*
5. In **Conditions** section on the drop down after **WHERE** select **Backendname**
6. Set it to be equal (=) to *Send Message* and click **Save Changes.**

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

#### CREATE SENDING TRIGGER BASED ON BUTTON CLICK EVENTS FILTER

1. Navigate to **Triggers** tab in the filter created and click **Create new trigger**
2. Name the trigger as *Send Message*
3. From **Operations** dropdown select pre-created *Send Message* operation and click **Add Operation**
4. **Trigger Scope** menu: select **Events**
5. **Trigger Mode** menu: select **Automatic**
6. **On new data appearing** select **Instantly**
7. Click **Start automatic mode** and **Save** trigger, click **Close.**

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

#### CHECK THE RESULT

1. Add new screen in Demo app
2. Drag and Drop [Text Input](https://mobsted-2.gitbook.io/knowledge-base/references/intro-placeholder/constructor_elements#text-input-and-text-area) element to the screen, set it's properties:
   * **Backendname** = *Email*
   * **Placeholder** = email address
3. Click **Save Screen**
4. Drag and Drop [Button](https://mobsted-2.gitbook.io/knowledge-base/references/intro-placeholder/constructor_elements#button) element to the screen, set it's properties:
   * **Backendname** = *Send Message*
   * **Caption** = *Submit*
5. Click **Actions,** then open **Add new action** drop down and select **Create Event**
6. &#x20;Set the name of the event = ***Send Message***
7. Click **Save**
8. Click **Save Screen**
9. Click **Preview** button to launch the app from the current screen to check it works
10. Click the button to execute the trigger and make sure you've received the message to your phone.

#### MENTIONED ARTICLES

* [Objects](https://mobsted-2.gitbook.io/knowledge-base/references/intro-placeholder/objects)
* [Events](https://mobsted-2.gitbook.io/knowledge-base/references/intro-placeholder/events)
* [Statuses](https://mobsted-2.gitbook.io/knowledge-base/basics/introduction/broken-reference)
* [Smart Filters](https://mobsted-2.gitbook.io/knowledge-base/basics/introduction/broken-reference)
* [Constructor elements](https://mobsted-2.gitbook.io/knowledge-base/references/intro-placeholder/constructor_elements)
* [Hashtags](https://mobsted-2.gitbook.io/knowledge-base/references/intro-placeholder/hashtags)
