Skip to content

How to send file by URL#

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 file by URL#

Link to the example: sendFileByUrl.cpp.

nlohmann::json SendFileByUrlJson{
    { "chatId","71234567890@c.us" },
    { "urlFile","https://sw-media-1101.storage.yandexcloud.net/1101123456s/13238852-be73-4f8c-a973-966d2730ce15.png" },
    { "fileName","1.png" },
    { "caption","I use GREEN-API to send this message to you!" }
    };

    greenapi::Response sendFileByUrl = instance1101000001.sending.sendFileByUrl(SendFileByUrlJson);

    if (sendFileByUrl.error) {
        std::cout << "sendFileByUrl error: {status code: " << sendFileByUrl.status_code << ", request time: " << sendFileByUrl.total_time << ", body: " << sendFileByUrl.bodyStr << "}" << "\n" << std::endl;
    }
    else {
        std::cout << "\tidMessage: " << sendFileByUrl.bodyJson["idMessage"] << 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