[go: up one dir, main page]

Skip to content

How to send a message#

Installing#

To build and install the library to your project use the instruction

Import#

Specify the directory of GREEN-API library's header file

#include "greenapi.hpp"

Examples#

How to initialize an object#

To initialize an object it is required to use apiUrl and mediaUrl parameters specifically for your instance from your console, that way you will get the most stable API work and minimal response time.

greenapi::GreenApi instance1101000001{
    "https://api.green-api.com",
    "https://media.green-api.com",
    "1101123456",
    "87be9e9532fc49748f2a44b9242e55f2e89f4bf97ed6498f80"
    };

How to send a message#

Link to the example: main.cpp.

Almost in every method you have to pass objects in a nlohmann::json format. Required and optional parameters are specified in the documentation and in the examples.

nlohmann::json sendMessageJson{
        { "chatId","71234567890@c.us" },
        { "message","I use GREEN-API to send this message to you!" }
    };
    greenapi::Response sendMessage = instance1101000001.sending.sendMessage(sendMessageJson);

    if (sendMessage.error) {
        std::cout << "sendMessage error: {status code: " << sendMessage.status_code << ", request time: " << sendMessage.total_time << ", body: " << sendMessage.bodyStr << "}" << "\n" << std::endl;
    }
    else {
        std::cout << "\tidMessage: " << sendMessage.bodyJson["idMessage"] << "\n" << std::endl;
    }

Pay attention that all the library's methods return structure of greenapi::Response type. To control the programm's work, check the method's execution, error field.

Examples list#

Description Link to the example
How to send message main.cpp
How to send file by upload sendFileByUpload.cpp
How to send file by URL sendFileByUrl.cpp
How to receive notification receiveIncomingNotifications.cpp
How to create group createGroupAndSendMessage.go