-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
RetrievePhoneNumberExample.java
59 lines (35 loc) · 2.07 KB
/
RetrievePhoneNumberExample.java
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
package com.whatsapp.api.examples;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.whatsapp.api.WhatsappApiFactory;
import com.whatsapp.api.impl.WhatsappBusinessManagementApi;
import static com.whatsapp.api.TestConstants.PHONE_NUMBER_ID;
import static com.whatsapp.api.TestConstants.TOKEN;
import static com.whatsapp.api.TestConstants.WABA_ID;
public class RetrievePhoneNumberExample {
public static void main(String[] args) throws JsonProcessingException {
WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN);
WhatsappBusinessManagementApi whatsappBusinessManagementApi = factory.newBusinessManagementApi();
// one phone number
retrieveOne(whatsappBusinessManagementApi);
// one phone number with specifc fields
retrieveOneWithSpecificFields(whatsappBusinessManagementApi);
// a list of phone numbers
retrieveAll(whatsappBusinessManagementApi);
}
private static void retrieveOne(WhatsappBusinessManagementApi whatsappBusinessManagementApi) throws JsonProcessingException {
var phoneNumber = whatsappBusinessManagementApi.retrievePhoneNumber(PHONE_NUMBER_ID);
ObjectMapper mapper = new ObjectMapper();
System.out.println(mapper.writeValueAsString(phoneNumber));
}
private static void retrieveOneWithSpecificFields(WhatsappBusinessManagementApi whatsappBusinessManagementApi) throws JsonProcessingException {
var phoneNumber = whatsappBusinessManagementApi.retrievePhoneNumber(PHONE_NUMBER_ID, "name_status", "verified_name");
ObjectMapper mapper = new ObjectMapper();
System.out.println(mapper.writeValueAsString(phoneNumber));
}
private static void retrieveAll(WhatsappBusinessManagementApi whatsappBusinessManagementApi) throws JsonProcessingException {
var phoneNumbers = whatsappBusinessManagementApi.retrievePhoneNumbers(WABA_ID);
ObjectMapper mapper = new ObjectMapper();
System.out.println(mapper.writeValueAsString(phoneNumbers));
}
}