fix(wuzapi): update webhook events and url for automation
This commit is contained in:
parent
fb4df77b28
commit
39189e2e42
@ -9,12 +9,12 @@ module Wuzapi
|
|||||||
def provision(name)
|
def provision(name)
|
||||||
user_token = SecureRandom.hex(32)
|
user_token = SecureRandom.hex(32)
|
||||||
response = @client.create_user(@admin_token, name, user_token)
|
response = @client.create_user(@admin_token, name, user_token)
|
||||||
|
|
||||||
# Wuzapi returns the user object, or we assume success if no error raised.
|
# Wuzapi returns the user object, or we assume success if no error raised.
|
||||||
# The response structure depends on Wuzapi. Assuming it returns { "ID": "...", ... } or similar.
|
# The response structure depends on Wuzapi. Assuming it returns { "ID": "...", ... } or similar.
|
||||||
# Based on plan, we just need to know it succeeded.
|
# Based on plan, we just need to know it succeeded.
|
||||||
# We return the generated data to be saved.
|
# We return the generated data to be saved.
|
||||||
|
|
||||||
{
|
{
|
||||||
wuzapi_user_id: response['ID'] || response['id'], # Adjust based on actual response if known, strictly fallback
|
wuzapi_user_id: response['ID'] || response['id'], # Adjust based on actual response if known, strictly fallback
|
||||||
wuzapi_user_token: user_token
|
wuzapi_user_token: user_token
|
||||||
@ -25,8 +25,10 @@ module Wuzapi
|
|||||||
# Host logic needs to come from GlobalConfig or Rails.application.routes
|
# Host logic needs to come from GlobalConfig or Rails.application.routes
|
||||||
# Ideally passed in or resolved.
|
# Ideally passed in or resolved.
|
||||||
base_host = ENV.fetch('FRONTEND_URL', 'http://localhost:3000')
|
base_host = ENV.fetch('FRONTEND_URL', 'http://localhost:3000')
|
||||||
webhook_url = "#{base_host}/webhooks/wuzapi/#{inbox_id}?secret=#{webhook_secret}"
|
inbox = Inbox.find(inbox_id)
|
||||||
|
phone_number = inbox.channel.phone_number.delete('+')
|
||||||
|
webhook_url = "#{base_host}/webhooks/whatsapp/#{phone_number}"
|
||||||
|
|
||||||
@client.set_webhook(user_token, webhook_url)
|
@client.set_webhook(user_token, webhook_url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -62,7 +62,7 @@ module Wuzapi
|
|||||||
|
|
||||||
def set_webhook(user_token, webhook_url)
|
def set_webhook(user_token, webhook_url)
|
||||||
# Wuzapi expects key 'webhook' per documentation.
|
# Wuzapi expects key 'webhook' per documentation.
|
||||||
payload = { 'webhook' => webhook_url, 'events' => ['All'] }
|
payload = { 'webhook' => webhook_url, 'events' => %w[Message ReadReceipt Presence HistorySync ChatPresence] }
|
||||||
request(:post, '/webhook', payload, user_auth_headers(user_token))
|
request(:post, '/webhook', payload, user_auth_headers(user_token))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user