Zig
Zig
WhatsApp Cloud API Send Message
See more WhatsApp Examples
Demonstrates how to send a message using the WhatsApp Cloud API (Business App)Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// The following JSON is sent in the request body.
// {
// "messaging_product": "whatsapp",
// "to": "16302581871",
// "type": "template",
// "template": {
// "name": "hello_world",
// "language": {
// "code": "en_US"
// }
// }
// }
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("messaging_product", "whatsapp") catch {};
json.updateString("to", "15555555555") catch {};
json.updateString("type", "template") catch {};
json.updateString("template.name", "hello_world") catch {};
json.updateString("template.language.code", "en_US") catch {};
http.setAuthToken("EAANrS5....yFB9Ma");
http.setRequestHeader("Content-Type", "application/json");
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpJson("POST", "https://graph.facebook.com/v18.0/111111111111111/messages", json, "application/json", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("{d}\n", .{resp.getStatusCode()});
std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
// Here's a screenshot of our WhatsApp test app.
//
}