C
C
WhatsApp Cloud API Send Message
See more WhatsApp Examples
Demonstrates how to send a message using the WhatsApp Cloud API (Business App)Chilkat C Downloads
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttp http;
HCkJsonObject json;
HCkHttpResponse resp;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
// The following JSON is sent in the request body.
// {
// "messaging_product": "whatsapp",
// "to": "16302581871",
// "type": "template",
// "template": {
// "name": "hello_world",
// "language": {
// "code": "en_US"
// }
// }
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"messaging_product","whatsapp");
CkJsonObject_UpdateString(json,"to","15555555555");
CkJsonObject_UpdateString(json,"type","template");
CkJsonObject_UpdateString(json,"template.name","hello_world");
CkJsonObject_UpdateString(json,"template.language.code","en_US");
CkHttp_putAuthToken(http,"EAANrS5....yFB9Ma");
CkHttp_SetRequestHeader(http,"Content-Type","application/json");
resp = CkHttpResponse_Create();
success = CkHttp_HttpJson(http,"POST","https://graph.facebook.com/v18.0/111111111111111/messages",json,"application/json",resp);
if (success == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkHttpResponse_Dispose(resp);
return;
}
printf("%d\n",CkHttpResponse_getStatusCode(resp));
printf("%s\n",CkHttpResponse_bodyStr(resp));
// Here's a screenshot of our WhatsApp test app.
//
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkHttpResponse_Dispose(resp);
}