How to send file by upload#
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 upload#
To send file by upload, you have to pass the path to the file as the first parameter and the properties as the second parameter.
Link to the example: sendFileByUpload.cpp.
nlohmann::json sendFileByUploadFileJson{
{ "file","C:/1.png" }
};
nlohmann::json sendFileByUploadJson{
{ "chatId","71234567890@c.us" },
{ "caption","I use GREEN-API to send this message to you!" },
{ "fileName","1.png" }
};
greenapi::Response sendFileByUpload = instance1101000001.sending.sendFileByUpload(sendFileByUploadFileJson, sendFileByUploadJson);
if (sendFileByUpload.error) {
std::cout << "sendFileByUpload error: {status code: " << sendFileByUpload.status_code << ", request time: " << sendFileByUpload.total_time << ", body: " << sendFileByUpload.bodyStr << "}" << "\n" << std::endl;
}
else {
std::cout << "\tidMessage: " << sendFileByUpload.bodyJson["idMessage"] << std::endl;
std::cout << "\turlFile: " << sendFileByUpload.bodyJson["urlFile"] << "\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 |