Как отправить WhatsApp API с помощью Clojure

Введение

В этом руководстве мы создадим простые примеры для отправки сообщений через API WhatsApp с использованием Clojure.

Первое сообщение WhatsApp API с использованием Clojure

(require '[clj-http.client :as client])

(client/post "https://api.ultramsg.com/instance1150/messages/chat" {:form-params {:token "token_here"
                                                                                       :to "14155552671"
                                                                                       :body "WhatsApp API on UltraMsg.com works good"
                                                                                       :priority "10"
                                                                                       :referenceId "">

Отправить изображение

(require '[clj-http.client :as client])

(client/post "https://api.ultramsg.com/instance1150/messages/image" {:form-params {:token "token_here"
                                                                                        :to "14155552671"
                                                                                        :image "https://file-example.s3-accelerate.amazonaws.com/images/test.jpg"
                                                                                        :caption "image Caption"
                                                                                        :referenceId ""}})

Отправить документ

(require '[clj-http.client :as client])

(client/post "https://api.ultramsg.com/instance1150/messages/document" {:form-params {:token "token_here"
                                                                                           :to "14155552671"
                                                                                           :filename "hello.pdf"
                                                                                           :document "https://file-example.s3-accelerate.amazonaws.com/documents/cv.pdf"
                                                                                           :referenceId ""}})

Отправить аудио

(require '[clj-http.client :as client])

(client/post "https://api.ultramsg.com/instance1150/messages/audio" {:form-params {:token "token_here"
                                                                                        :to "14155552671"
                                                                                        :audio "https://file-example.s3-accelerate.amazonaws.com/audio/2.mp3"
                                                                                        :referenceId ""}})

Отправить голос

(require '[clj-http.client :as client])

(client/post "https://api.ultramsg.com/instance1150/messages/voice" {:form-params {:token "token_here"
                                                                                        :to "14155552671"
                                                                                        :audio "https://file-example.s3-accelerate.amazonaws.com/voice/oog_example.ogg"
                                                                                        :referenceId ""}})

Отправить видео

(require '[clj-http.client :as client])

(client/post "https://api.ultramsg.com/instance1150/messages/video" {:form-params {:token "token_here"
                                                                                        :to "14155552671"
                                                                                        :video "https://file-example.s3-accelerate.amazonaws.com/video/test.mp4"
                                                                                        :referenceId ""}})
(require '[clj-http.client :as client])

(client/post "https://api.ultramsg.com/instance1150/messages/link" {:form-params {:token "token_here"
                                                                                       :to "14155552671"
                                                                                       :link "https://en.wikipedia.org/wiki/COVID-19"
                                                                                       :referenceId ""}})

Отправить контакт

(require '[clj-http.client :as client])

(client/post "https://api.ultramsg.com/instance1150/messages/contact" {:form-params {:token "token_here"
                                                                                          :to "14155552671"
                                                                                          :contact "[email protected]"
                                                                                          :referenceId ""}})

Отправить местоположение

(require '[clj-http.client :as client])

(client/post "https://api.ultramsg.com/instance1150/messages/location" {:form-params {:token "token_here"
                                                                                           :to "14155552671"
                                                                                           :address "ABC company \n Sixth floor , office 38"
                                                                                           :lat "25.197197"
                                                                                           :lng "55.2721877"
                                                                                           :referenceId ""}})

Отправить открытку

(require '[clj-http.client :as client])

(client/post "https://api.ultramsg.com/instance1150/messages/vcard" {:form-params {:token "token_here"
                                                                                        :to "14155552671"
                                                                                        :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 ""}})

наконец, вы можете ознакомиться с полной документацией по Whatsapp API и часто задаваемыми вопросами.