OCaml के साथ WhatsApp API कैसे भेजें

परिचय

इस ट्यूटोरियल में, हम OCaml का उपयोग करके WhatsApp API के माध्यम से संदेश भेजने के लिए सरल उदाहरण बनाएंगे।

OCaml का उपयोग कर पहला WhatsApp API संदेश

open Cohttp_lwt_unix
open Cohttp
open Lwt

let uri = Uri.of_string "https://api.ultramsg.com/instance1150/messages/chat" in
let body = Cohttp_lwt_body.of_string "token=token_here&to=966550883606&body=WhatsApp API on UltraMsg.com works good&priority=10&referenceId=" in

Client.call ~body `POST uri
>>= fun (res, body_stream) ->
  (* Do stuff with the result *)

छवि भेजें

open Cohttp_lwt_unix
open Cohttp
open Lwt

let uri = Uri.of_string "https://api.ultramsg.com/instance1150/messages/image" in
let body = Cohttp_lwt_body.of_string "token=token_here&to=966550883606&image=https://file-example.s3-accelerate.amazonaws.com/images/test.jpg&caption=image Caption&referenceId=" in

Client.call ~body `POST uri
>>= fun (res, body_stream) ->
  (* Do stuff with the result *)

दस्तावेज़ भेजें

open Cohttp_lwt_unix
open Cohttp
open Lwt

let uri = Uri.of_string "https://api.ultramsg.com/instance1150/messages/document" in
let body = Cohttp_lwt_body.of_string "token=token_here&to=966550883606&filename=hello.pdf&document=https://file-example.s3-accelerate.amazonaws.com/documents/cv.pdf&referenceId=" in

Client.call ~body `POST uri
>>= fun (res, body_stream) ->
  (* Do stuff with the result *)

ऑडियो भेजें

open Cohttp_lwt_unix
open Cohttp
open Lwt

let uri = Uri.of_string "https://api.ultramsg.com/instance1150/messages/audio" in
let body = Cohttp_lwt_body.of_string "token=token_here&to=966550883606&audio=https://file-example.s3-accelerate.amazonaws.com/audio/2.mp3&referenceId=" in

Client.call ~body `POST uri
>>= fun (res, body_stream) ->
  (* Do stuff with the result *)

आवाज भेजें

open Cohttp_lwt_unix
open Cohttp
open Lwt

let uri = Uri.of_string "https://api.ultramsg.com/instance1150/messages/voice" in
let body = Cohttp_lwt_body.of_string "token=token_here&to=966550883606&audio=https://file-example.s3-accelerate.amazonaws.com/voice/oog_example.ogg&referenceId=" in

Client.call ~body `POST uri
>>= fun (res, body_stream) ->
  (* Do stuff with the result *)

वीडियो भेजना

open Cohttp_lwt_unix
open Cohttp
open Lwt

let uri = Uri.of_string "https://api.ultramsg.com/instance1150/messages/video" in
let body = Cohttp_lwt_body.of_string "token=token_here&to=966550883606&video=https://file-example.s3-accelerate.amazonaws.com/video/test.mp4&referenceId=" in

Client.call ~body `POST uri
>>= fun (res, body_stream) ->
  (* Do stuff with the result *)
open Cohttp_lwt_unix
open Cohttp
open Lwt

let uri = Uri.of_string "https://api.ultramsg.com/instance1150/messages/link" in
let body = Cohttp_lwt_body.of_string "token=token_here&to=966550883606&link=https://en.wikipedia.org/wiki/COVID-19&referenceId=" in

Client.call ~body `POST uri
>>= fun (res, body_stream) ->
  (* Do stuff with the result *)

संपर्क भेजें

open Cohttp_lwt_unix
open Cohttp
open Lwt

let uri = Uri.of_string "https://api.ultramsg.com/instance1150/messages/contact" in
let body = Cohttp_lwt_body.of_string "token=token_here&to=966550883606&[email protected]&referenceId=" in

Client.call ~body `POST uri
>>= fun (res, body_stream) ->
  (* Do stuff with the result *)

स्थान भेजें

open Cohttp_lwt_unix
open Cohttp
open Lwt

let uri = Uri.of_string "https://api.ultramsg.com/instance1150/messages/location" in
let body = Cohttp_lwt_body.of_string "token=token_here&to=966550883606&address=ABC company \n Sixth floor , office 38&lat=25.197197&lng=55.2721877&referenceId=" in

Client.call ~body `POST uri
>>= fun (res, body_stream) ->
  (* Do stuff with the result *)

वीकार्ड भेजें

open Cohttp_lwt_unix
open Cohttp
open Lwt

let uri = Uri.of_string "https://api.ultramsg.com/instance1150/messages/vcard" in
let body = Cohttp_lwt_body.of_string "token=token_here&to=966550883606&vcard= BEGIN:VCARD\nVERSION:3.0\nN:lastname;firstname\nFN:firstname lastname\nTEL;TYPE=CELL;waid=14000000001:14000000002\nNICKNAME:nickname\nBDAY:01.01.1987\nX-GENDER:M\nNOTE:note\nADR;TYPE=home:;;;;;;\nADR;TYPE=work_:;;;;;;\nEND:VCARD&referenceId=" in

Client.call ~body `POST uri
>>= fun (res, body_stream) ->
  (* Do stuff with the result *)

अंत में, आप पूर्ण व्हाट्सएप एपीआई दस्तावेज़ीकरण और अक्सर पूछे जाने वाले प्रश्न देख सकते हैं।