Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # WhatsBroadcast API class, allows to send messages to whatsapp
- class WhatsbroadcastApi
- def initialize
- @base_uri = URI.parse(ENV['whatsbroadcast_base_url'])
- @client_secret = ENV['whatsbroadcast_key']
- end
- # Send message to WhatsBroadcast client
- def self.send_message(user_id, message)
- @api ||= WhatsbroadcastApi.new
- @api.send_message(user_id, message)
- end
- def send_message(user_id, message)
- request_body = {apikey: @client_secret,id: user_id, message: message, conversation_status: true}
- HTTParty.post("#{@base_uri}/chat", body: request_body).parsed_response
- end
- # Enables WebHook
- def self.enable_webhook(webhook_url, webhook_email)
- @api ||= WhatsbroadcastApi.new
- @api.enable_webhook(webhook_url, webhook_email)
- end
- def enable_webhook(webhook_url, webhook_email)
- request_body = {apikey: @client_secret, webhook_url: webhook_url, status:1, webhook_email: webhook_email, send_test: 1}
- HTTParty.put("#{@base_uri}/channel/webhook", body: request_body).parsed_response
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement