All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.greenapi.client.examples.CreateGroupSendMessageExample Maven / Gradle / Ivy

There is a newer version: 0.1.8
Show newest version
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();
        groupMembers.add("[email protected]");
        groupMembers.add("[email protected]");
        groupMembers.add("[email protected]");

        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());
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy