---
title: "How to configure the SMS feature"
canonical: "https://help.fieldbuddy.com/space/FBDOCS/4787109903/How%20to%20configure%20the%20SMS%20feature"
format: markdown
---
## 📱 What are the possibilities

FieldBuddy can sent SMS messages to phone-numbers via the platform: [https://bird.com/](https://bird.com/).

![image](media://de3033c6-6b9b-4100-a140-fc9a3602c63d)

This feature can be configured via the **Configuration Panel** in FieldBuddy Service Center. 

There are four tabs available:

- **Set-up credentials **in which an API Token from Messagebird is entered (see how-to how to obtain the token)
- **Logs** that are created each time a SMS is sent
- **Quote Balance **in which you can see how much credits the account has.
- **Settings **where two default triggers can be enabled/disabled

SMS is set by default from FieldBuddy as originator, but it could be changed by renaming custom label `Messaging_Originator`

## Default Triggers

The two default triggers that are available are listed and explained below. No coding is required. The field that is used in these scenario’s are Phone fields on related Account record:

- For SR-based Work Orders - WO.SR.IP.LOC.Account.Phone
- For LOC-based Work Orders - WO.LOC.Account.Phone

### Apex Trigger: Notify technician arrivals

This is an Apex trigger on Work Order. It can be enabled via the Configuration Panel in Settings tab

The trigger does:

1. Check its enabled in the Configuration Panel
2. When a Work Order is set changed from **NOT** the status `ON_THE_GO` to `ON_THE_GO `and `FIELDBUDDY__Notified_Arrival__c `on Work Order is FALSE; a SMS is sent.
3. The `FIELDBUDDY__Notified_Arrival__c` is automatically set to TRUE when a SMS is sent.

The text in the SMS is coming from the custom label: `arrival_notification`. This can be modified via Setup > Custom Labels.

Default value: 

> Jouw geplande afspraak voor vandaag is onderweg, met vriendelijke groet, FieldBuddy

When SMS is sent – a Task is created on a Work Order with type SMS and status Completed, and description as content of a message.

### Scheduled Job: Notify appointments

This is a scheduled Apex job. 

How to schedule it via the Developer Console (run anonymous apex):

- `FIELDBUDDY.cls_External.scheduleWOAppointmentNotification('SMS', '<sample cron>');`

Replace <sample cron> with '`0 0 18 * * ?`' to run it daily at 18:00.

The job does: 

1. Check if its enabled in the Configuration Panel
2. Query all the Resource Unit Assignments where `FIELDBUDDY__Notified_Appointment__c` on RUA is FALSE and are scheduled for the **next** day.
3. It will sent a SMS on the time the job is scheduled, for example: 18:00 in the evening. So it will notify customers the day before, at 18:00, that a technician will be there.
4. Once sent,  `FIELDBUDDY__Notified_Appointment__c` is updated to TRUE on Resource Unit Assignment.

The text in the SMS is coming from the custom label: `Appointment_Notification` and `Appointment_Notification_Regards`. This can be modified via SETUP.

Format of the SMS is: 

```
Appointment_Notification +  ' ' + [RUA START TIME]format('hh:mm') + Appointment_Notification_Regards + ', ' + org.Name
```

Default value: 

> Je hebt een afspraak voor morgen gepland om 16:30, Met vriendelijke groet FieldBuddy

When SMS is sent – a Task is created on a parent Work Order with type SMS and status Completed, and description as content of a message.

## Custom Trigger

Custom triggers can be built via Apex or a Flow. Use **FieldBuddyMessageSenderInvocable** Class.

This is unmanaged, and should be deployed first

```
public class FieldBuddyMessageSenderInvocable {
    @InvocableMethod(label='Send Messages' description='Send SMS')
    public static List<String> sendMessages(List<MessageParameter> receivers) {
        List<String> response = new List<String>();
        for(Integer i = 0; i < receivers.size(); i++) {
            response.add('OK');
        }
        System.enqueueJob(new SendMessageQueueable(receivers));
        return response;
    }
    public class MessageParameter {
        @InvocableVariable(required=true)
        public String recipient ;
        @InvocableVariable(required=true)
        public String body ;
        @InvocableVariable(required=true)
        public String action ;
        @InvocableVariable(required=true)
        public String recordId ;
    }

    public class SendMessageQueueable implements Queueable, Database.AllowsCallouts {
        public List<MessageParameter> messages;
        public SendMessageQueueable(List<MessageParameter> msgs) {
            this.messages = msgs;
        }

        public void execute(QueueableContext cntx) {
           for(Integer i = 0; i < this.messages.size(); i++) {
                String res = FIELDBUDDY.cls_External.sendMessage(
                  this.messages.get(i).recipient,
                  this.messages.get(i).body,
                  this.messages.get(i).action,
                  this.messages.get(i).recordId
                );
            }
        }
    }

}
```

Parameters:

- `recipient` - phone number of recipient
- `body` - SMS message content
- `action` - not used in SMS, but it is set to FIELDBUDDY__Action__c field for system log in case of success/error
- `recordId` - not used in SMS, but it is set to FIELDBUDDY__Diagnostic_Data__c field for system log in case of success/error


<details>
<summary>Unit test - FieldBuddyInvocableMessageSenderTest</summary>

```
@IsTest
private class FieldBuddyInvocableMessageSenderTest {
    @IsTest
    private static void testSendSMSJob() {
        //GIVEN
        List<FieldBuddyMessageSenderInvocable.MessageParameter> parameters = new List<FieldBuddyMessageSenderInvocable.MessageParameter>();
		FieldBuddyMessageSenderInvocable.MessageParameter mp = new FieldBuddyMessageSenderInvocable.MessageParameter();
        mp.recipient = '+31612345670';
        mp.body = 'Test SMS';
        mp.action = 'Test SMS';
        mp.recordId = null;
		parameters.add(mp);
        
        //WHEN
        Test.startTest();
        List<String> result = FieldBuddyMessageSenderInvocable.sendMessages(parameters);
        Test.stopTest();
        
        //THEN
        System.assertEquals(1, result.size());
        System.assertEquals('OK', result.get(0));
    }
}
```
</details>

## \uD83D\uDCD8 Instructions how to configure SMS in FieldBuddy

How to do basic set-up for FieldBuddy SMS. Go to this guide to create the account. 

[https://upperdeck.atlassian.net/wiki/spaces/FBDOCS/pages/5508464642](https://upperdeck.atlassian.net/wiki/spaces/FBDOCS/pages/5508464642)

## \uD83D\uDCCB Related articles



> Macro (contentbylabel)