Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. # WhatsBroadcast API class, allows to send messages to whatsapp
  2. class WhatsbroadcastApi
  3. def initialize
  4. @base_uri = URI.parse(ENV['whatsbroadcast_base_url'])
  5. @client_secret = ENV['whatsbroadcast_key']
  6. end
  7.  
  8. # Send message to WhatsBroadcast client
  9. def self.send_message(user_id, message)
  10. @api ||= WhatsbroadcastApi.new
  11. @api.send_message(user_id, message)
  12. end
  13.  
  14. def send_message(user_id, message)
  15. request_body = {apikey: @client_secret,id: user_id, message: message, conversation_status: true}
  16. HTTParty.post("#{@base_uri}/chat", body: request_body).parsed_response
  17. end
  18.  
  19. # Enables WebHook
  20. def self.enable_webhook(webhook_url, webhook_email)
  21. @api ||= WhatsbroadcastApi.new
  22. @api.enable_webhook(webhook_url, webhook_email)
  23. end
  24.  
  25. def enable_webhook(webhook_url, webhook_email)
  26. request_body = {apikey: @client_secret, webhook_url: webhook_url, status:1, webhook_email: webhook_email, send_test: 1}
  27. HTTParty.put("#{@base_uri}/channel/webhook", body: request_body).parsed_response
  28. end
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement