-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateGroupSendMessageExample.java
40 lines (33 loc) · 1.27 KB
/
CreateGroupSendMessageExample.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
package com.greenapi.client.examples;
import com.greenapi.client.pkg.api.GreenApi;
import com.greenapi.client.pkg.models.request.CreateGroupReq;
import com.greenapi.client.pkg.models.request.OutgoingMessage;
import lombok.extern.log4j.Log4j2;
import java.util.ArrayList;
@Log4j2
class CreateGroupSendMessageExample {
private void createGroupAndSendMessage(GreenApi greenApi) {
var groupMembers = new ArrayList<String>();
groupMembers.add("11001234567@c.us");
groupMembers.add("11001234566@c.us");
groupMembers.add("11001234565@c.us");
var group = greenApi.groups.createGroup(
CreateGroupReq.builder()
.groupName("Test Group")
.chatIds(groupMembers)
.build())
.getBody();
if (group != null) {
var message = greenApi.sending.sendMessage(
OutgoingMessage.builder()
.chatId(group.getChatId())
.message("hola a todos")
.build())
.getBody();
if (message != null) {
log.info("Create group: " + group.getCreated() +
"\nSend message: " + message.getIdMessage());
}
}
}
}