Whatsapp API بإستخدام لغة Ruby

Whatsapp API بإستخدام لغة Ruby

في هذه المقالة ، سنقوم بإنشاء أمثلة بسيطة لإرسال رسائل WhatsApp API باستخدام Ruby.

في البداية ، يجب التأكد من أن مكتبة net / http جاهزة لأننا سنستخدم هذه المكتبة في هذه المقالة لإرسال رسائل الواتس اب API إلى بوابة Ultramsg بإستخدام لغة روبي .

أول رسالة WhatsApp باستخدام Ruby

require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://api.ultramsg.com/instance1316/messages/chat")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/x-www-form-urlencoded'
request.body = "token=5v941eyo9eqixrsi&to=14155552671&body=WhatsApp API on UltraMsg.com works good&priority=10&referenceId="

response = http.request(request)
puts response.read_body

عندما يتم تنفيذ الكود السابق ، وإذا تم إرسال الرسالة بنجاح ، فسيكون الرد كما يلي:

{"sent":"true","message":"ok","id":47}

إرسال صورة

require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://api.ultramsg.com/instance1316/messages/image")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/x-www-form-urlencoded'
request.body = "token=5v941eyo9eqixrsi&to=14155552671&image=https://file-example.s3-accelerate.amazonaws.com/images/test.jpg&caption=image Caption&referenceId="

response = http.request(request)
puts response.read_body

إرسال ملف

require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://api.ultramsg.com/instance1316/messages/document")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/x-www-form-urlencoded'
request.body = "token=5v941eyo9eqixrsi&to=14155552671&filename=hello.pdf&document=https://file-example.s3-accelerate.amazonaws.com/documents/cv.pdf&referenceId="

response = http.request(request)
puts response.read_body

إرسل صوت

require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://api.ultramsg.com/instance1316/messages/audio")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/x-www-form-urlencoded'
request.body = "token=5v941eyo9eqixrsi&to=14155552671&audio=https://file-example.s3-accelerate.amazonaws.com/audio/2.mp3&referenceId="

response = http.request(request)
puts response.read_body

إرسال تسجيل صوتي

require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://api.ultramsg.com/instance1316/messages/voice")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/x-www-form-urlencoded'
request.body = "token=5v941eyo9eqixrsi&to=14155552671&audio=https://file-example.s3-accelerate.amazonaws.com/voice/oog_example.ogg&referenceId="

response = http.request(request)
puts response.read_body

إرسال فيديو

require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://api.ultramsg.com/instance1316/messages/video")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/x-www-form-urlencoded'
request.body = "token=5v941eyo9eqixrsi&to=14155552671&video=https://file-example.s3-accelerate.amazonaws.com/video/test.mp4&referenceId="

response = http.request(request)
puts response.read_body
require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://api.ultramsg.com/instance1316/messages/link")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/x-www-form-urlencoded'
request.body = "token=5v941eyo9eqixrsi&to=14155552671&link=https://en.wikipedia.org/wiki/COVID-19&referenceId="

response = http.request(request)
puts response.read_body

إرسال جهة اتصال

require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://api.ultramsg.com/instance1316/messages/contact")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/x-www-form-urlencoded'
request.body = "token=5v941eyo9eqixrsi&to=14155552671&[email protected]&referenceId="

response = http.request(request)
puts response.read_body

إرسال موقع جغرافي

require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://api.ultramsg.com/instance1316/messages/location")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/x-www-form-urlencoded'
request.body = "token=5v941eyo9eqixrsi&to=14155552671&address=ABC company \n Sixth floor , office 38&lat=25.197197&lng=55.2721877&referenceId="

response = http.request(request)
puts response.read_body

إرسال Vcard

require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://api.ultramsg.com/instance1316/messages/vcard")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/x-www-form-urlencoded'
request.body = "token=5v941eyo9eqixrsi&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="

response = http.request(request)
puts response.read_body

أخيرا يمكن مشاهدة دليل وثائق Whatsapp API Documentation. بالإضافة للأسئلة الشائعة FAQ