Java

This application will demonstrate how to implement endpoints to start receiving callbacks from Live Link 365.

This is not a production-ready application, please take your time to read about SpringBoot to make it meet production standards and your business requirements.

To follow this tutorial, you should have basic understanding of:
  • Java
  • SpringBoot

Steps

Code

keyboard_arrow_down
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package sinch.livelink365.callbacks;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import sinch.livelink365.callbacks.entity.Appointment;
import sinch.livelink365.callbacks.service.AppointmentService;
import sinch.livelink365.callbacks.service.MessageService;

import java.io.IOException;

// _Step_1
@SpringBootApplication
public class CallbacksApplication {

    public static void main(String[] args) {

        SpringApplication.run(CallbacksApplication.class, args);

        try {
            MessageService service = new MessageService();
            AppointmentService appointmentService = new AppointmentService();
            appointmentService.sendAppointmentMessage();
        } catch (IOException ex) {
            System.out.println(ex);
        }
    }
}
# _Step_2
baseUrl=https://livelink.sapdigitalinterconnect.com/api
# Insert your generated app key here
appKey=
# Insert your generated app secret here
appSecret=
# Default number that will be used to send message
defaultOrigin=
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package sinch.livelink365.callbacks.entity;

// _Step_3
public class StatusBody {
    private String messageId;
    private String message;
    private String msisdn;

    public StatusBody() {}

    public StatusBody(String messageId, String message, String msisdn){
        this.setMessageId(messageId);
        this.setMessage(message);
        this.setMsisdn(msisdn);
    }


    public String getMessageId() {
        return messageId;
    }

    public void setMessageId(String messageId) {
        this.messageId = messageId;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getMsisdn() {
        return msisdn;
    }

    public void setMsisdn(String msisdn) {
        this.msisdn = msisdn;
    }
}
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
package sinch.livelink365.callbacks.entity;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;

import java.sql.Timestamp;
import java.util.Date;

// _Step_4
public class IncomingBody {

    public IncomingBody() {}

    public IncomingBody(String messageId, String message, String msisdn, String originatingAddress, Parameters parameters, ReceivedTime receivedTime) {
        this.messageId = messageId;
        this.message = message;
        this.msisdn = msisdn;
        this.originatingAddress = originatingAddress;
        this.parameters = parameters;
        this.receivedTime = receivedTime;
    }

    @JsonProperty
    private String messageId;

    @JsonProperty
    private String message;

    @JsonProperty
    private String msisdn;

    @JsonProperty
    private String originatingAddress;

    @JsonProperty
    private Parameters parameters;

    @JsonProperty
    private ReceivedTime receivedTime;

    public String getMessageId() {
        return messageId;
    }

    @JsonSetter("messageId")
    public void setMessageId(String messageId) {
        this.messageId = messageId;
    }

    public String getMessage() {
        return message;
    }

    @JsonSetter("message")
    public void setMessage(String message) {
        this.message = message;
    }

    public String getMsisdn() {
        return msisdn;
    }

    @JsonSetter("msisdn")
    public void setMsisdn(String msisdn) {
        this.msisdn = msisdn;
    }

    public String getOriginatingAddress() {
        return originatingAddress;
    }

    @JsonSetter("originatingAddress")
    public void setOriginatingAddress(String originatingAddress) {
        this.originatingAddress = originatingAddress;
    }

    public Parameters getParameters() {
        return parameters;
    }

    @JsonSetter("parameters")
    public void setParameters(Parameters parameters) {
        this.parameters = parameters;
    }

    public ReceivedTime getReceivedTime() {
        return receivedTime;
    }

    @JsonSetter("receivedTime")
    public void setReceivedTime(ReceivedTime receivedTime) {
        this.receivedTime = receivedTime;
    }


    public static class Code {
        @JsonProperty
        private String mcc;

        @JsonProperty
        private String mnc;

        public Code() {}

        public Code (String mcc, String mnc){
            this.mnc = mnc;
            this.mcc = mcc;
        }

        public String getMcc() {
            return mcc;
        }

        @JsonSetter("mcc")
        public void setMcc(String mcc) {
            this.mcc = mcc;
        }

        public String getMnc() {
            return mnc;
        }

        @JsonSetter("mnc")
        public void setMnc(String mnc) {
            this.mnc = mnc;
        }
    }

    public static class Operator {
        @JsonProperty
        private Code code;

        @JsonProperty
        private String standard;

        public Operator() {}

        public Operator (Code code, String standard){
            this.code = code;
            this.standard = standard;
        }

        public Code getCode() {
            return code;
        }

        @JsonSetter("code")
        public void setCode(Code code) {
            this.code = code;
        }

        public String getStandard() {
            return standard;
        }

        @JsonSetter("standard")
        public void setStandard(String standard) {
            this.standard = standard;
        }
    }

    public static class ReceivedTime {
        @JsonProperty
        private String Date;

        @JsonProperty
        private String Time;

        public ReceivedTime() {}

        public ReceivedTime(String Date, String Time){
            this.Date = Date;
            this.Time = Time;
        }

        public String getDate() {
            return Date;
        }

        @JsonSetter("Date")
        public void setDate(String date) {
            Date = date;
        }

        public String getTime() {
            return Time;
        }

        @JsonSetter("Time")
        public void setTime(String time) {
            Time = time;
        }
    }

    public static class Parameters {
        @JsonProperty
        private String accountId;

        @JsonProperty
        private String dcs;

        @JsonProperty
        private String keyword;

        @JsonProperty
        private String messageClass;

        @JsonProperty
        private String messageId;

        @JsonProperty
        private Operator operator;

        @JsonProperty
        private String receivedServiceNumber;

        @JsonProperty
        private ReceivedTime receivedTime;

        @JsonProperty
        private String udh;

        public Parameters() {}

        public Parameters(String accountId, String dcs, String keyword, String messageClass, String messageId, Operator operator, String receivedServiceNumber, ReceivedTime receivedTime, String udh) {
            this.accountId = accountId;
            this.dcs = dcs;
            this.keyword = keyword;
            this.messageClass = messageClass;
            this.messageId = messageId;
            this.operator = operator;
            this.receivedServiceNumber = receivedServiceNumber;
            this.receivedTime = receivedTime;
            this.udh = udh;
        }

        public String getAccountId() {
            return accountId;
        }

        @JsonSetter("accountId")
        public void setAccountId(String accountId) {
            this.accountId = accountId;
        }

        public String getDcs() {
            return dcs;
        }

        @JsonSetter("dcs")
        public void setDcs(String dcs) {
            this.dcs = dcs;
        }

        public String getKeyword() {
            return keyword;
        }

        @JsonSetter("keyword")
        public void setKeyword(String keyword) {
            this.keyword = keyword;
        }

        public String getMessageClass() {
            return messageClass;
        }

        @JsonSetter("messageClass")
        public void setMessageClass(String messageClass) {
            this.messageClass = messageClass;
        }

        public String getMessageId() {
            return messageId;
        }

        @JsonSetter("messageId")
        public void setMessageId(String messageId) {
            this.messageId = messageId;
        }

        public Operator getOperator() {
            return operator;
        }

        @JsonSetter("operator")
        public void setOperator(Operator operator) {
            this.operator = operator;
        }

        public String getReceivedServiceNumber() {
            return receivedServiceNumber;
        }

        @JsonSetter("receivedServiceNumber")
        public void setReceivedServiceNumber(String receivedServiceNumber) {
            this.receivedServiceNumber = receivedServiceNumber;
        }

        public ReceivedTime getReceivedTime() {
            return receivedTime;
        }

        @JsonSetter("receivedTime")
        public void setReceivedTime(ReceivedTime receivedTime) {
            this.receivedTime = receivedTime;
        }

        public String getUdh() {
            return udh;
        }

        @JsonSetter("udh")
        public void setUdh(String udh) {
            this.udh = udh;
        }
    }

}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package sinch.livelink365.callbacks.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sinch.livelink365.callbacks.entity.StatusBody;
import sinch.livelink365.callbacks.service.StatusService;

// _Step_5
@RestController
public class StatusController {

    @Autowired
    protected StatusService statusService;

    @PostMapping("/messages/status")
    public void receiveStatusCallback(@RequestBody StatusBody statusCallback) {
        statusService.receiveStatusCallback(statusCallback);
    }
}
//------------StatusService.java----------//
package sinch.livelink365.callbacks.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import sinch.livelink365.callbacks.entity.StatusBody;

@Service
public class StatusService {
    protected final Logger logger = LoggerFactory.getLogger(getClass());

    public void receiveStatusCallback(StatusBody status){
        logger.info(status.getMessage());
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package sinch.livelink365.callbacks.service;

import sinch.livelink365.callbacks.entity.*;

import java.io.IOException;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;

// _Step_6
public class AppointmentService {

    public AppointmentService() {};

    public void sendAppointmentMessage() throws IOException{
        Doctor doctor = new Doctor("1", "Christina", "Yang", "Cardiology");
        Person patient = new Person("2", "Steven", "Gorwell", "+50431401307");

        Calendar cal = Calendar.getInstance();
        cal.set(2018, 8, 18, 16, 30);

        Timestamp bookingDate = new Timestamp(cal.getTimeInMillis());

        Appointment appointment = new Appointment(doctor, patient, bookingDate);

        LocalDate date = Instant.ofEpochMilli(appointment.getDate().getTime()).atZone(ZoneId.systemDefault()).toLocalDate();
        LocalDateTime time = appointment.getDate().toLocalDateTime();

        String message = String.format("Mr/Ms %s, you have an appointment with Dr. %s (%s), schedule on %s at %s.",
                                    appointment.getPatient().getFullName(),
                                    appointment.getDoctor().getFullName(),
                                    appointment.getDoctor().getSpecialization(),
                                    date.format(DateTimeFormatter.ofPattern("E, dd-MM-u")),
                                    time.format(DateTimeFormatter.ofPattern("hh:mm a")));

        MessageService messageService = new MessageService();
        messageService.sendMessage(message, appointment.getPatient().getPhoneNumber(), "");
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package sinch.livelink365.callbacks;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import sinch.livelink365.callbacks.entity.Appointment;
import sinch.livelink365.callbacks.service.AppointmentService;
import sinch.livelink365.callbacks.service.MessageService;

import java.io.IOException;

// _Step_7
@SpringBootApplication
public class CallbacksApplication {

    public static void main(String[] args) {

        SpringApplication.run(CallbacksApplication.class, args);

        try {
            MessageService service = new MessageService();
            AppointmentService appointmentService = new AppointmentService();
            appointmentService.sendAppointmentMessage();
        } catch (IOException ex) {
            System.out.println(ex);
        }
    }
}