i want to create a ghl marketplace app for custom cinversations ,
i already created app for signalwire and in /help/GHL-token-help/latest-credentials-signalwire.txt i add all credentials.
now i want to create a larval backend for my marketplace app so its hendal GHL agency and subaccounts both.
#Oauth
- So first we need to create callback endpoint to hendal oauth for agency and subaccounts both so we use 2 tables one for agency tokens and one for subaccount tokens , and aslo create helper that hendel token validationa nd return valid token and refresh on expire and alwasy return valid token and also update in db on expiry (get help form /help/GHL-token-help/callback.php and  /help/GHL-token-help/config.php ).  

#custom page for save signalwire credentials in db against installed account
- we need a endpoint for our custompage which we use to get signalwire credentials form user and save in db against GHL agency or subaccount so we know which credentials is for which account (i.e company or company subaccount). you can take help form /help/GHL-token-help/custom-page.php  and /help/GHL-token-help/getCredentials.php  
 -- in custom page we need to get signalwire credentials and after sucessfully store in db against installed account we endable test credentail button form which user can tests its credentials.


# webhook for hendle signalwire custom conversation push message
- we also need a endpoint for Delivery URL for our conversation provider.
  -- which send a payload like :
  {
  "userId": "0fEv8pWxnKf9guPQHSl6",
  "attachments": [],
  "contactId": "oIoZtSpc81XLKNUKXn8j",
  "locationId": "ZU1uFf3o1RK9wWjITncq",
  "messageId": "nAfvJCg9QLddYRsXVMUv",
  "type": "SMS",
  "conversationId": "4mLQJ7KFcwGElT0UcVyM",
  "phone": "+13141236547",
  "message": "hello",
  "customUserId": "",
  "conversationProviderId": "6a9eb66fb83299e7e2b81e33",
  "timestamp": "2026-09-07T16:07:32.782Z",
  "webhookId": "66e720be-3975-4fc6-bbea-6584160a4a44"
}

so we need proper handling or conversation .
- if need must read GHL api doc https://marketplace.gohighlevel.com/docs/ghl/conversations/conversations 
- must use GHL api version v3 for all endpoints and read latest api doc in browser if needed.

- For agency oauth as we have agency access token , so on agency login we show a side bar menu in our custom page and show subaccounts , get live subaccounts for GHL api using agency access token and shwo cards for subaccounts with its details like location id name etc like and a connect button , then on connect we generate location token for that subaccount and then show credentails form in next setp so agency user can hendal its own subaccounts , also show a dashbaord page with mimum 2 staks like total subaccounts connected etc like that. 
- for subaccount connetion we no need to show side bar menus that only for agency , subaccount just add its credentials tets and and our provider start working. 
- in short you can take refrence from twilio in GHL. ( just for understanding how conversation working).
- must sure our custom page not reachable outside GHL . 