Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
GHL issues a Company-scoped token (userType=Company) for bulk/agency installs even when Target User=Sub-account. This fix handles that case: 1. Detect userType=Company in HandleCallback 2. Call GET /locations/search to enumerate all company locations 3. For each location call POST /oauth/locationToken to get a Location-scoped token (userType=Location, includes locationId) 4. Store each location token individually in MongoDB This allows webhook delivery and status updates to work per-location without requiring the agency admin to re-install per sub-account. Co-Authored-By: Paperclip <noreply@paperclip.ing>
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package ghl
|
|
|
|
type TokenResponse struct {
|
|
AccessToken string `json:"access_token"`
|
|
RefreshToken string `json:"refresh_token"`
|
|
ExpiresIn int `json:"expires_in"`
|
|
TokenType string `json:"token_type"`
|
|
LocationID string `json:"locationId"`
|
|
CompanyID string `json:"companyId"`
|
|
UserType string `json:"userType"`
|
|
}
|
|
|
|
type LocationInfo struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type LocationsResponse struct {
|
|
Locations []LocationInfo `json:"locations"`
|
|
}
|
|
|
|
type OutboundMessageWebhook struct {
|
|
ContactID string `json:"contactId"`
|
|
LocationID string `json:"locationId"`
|
|
MessageID string `json:"messageId"`
|
|
Type string `json:"type"`
|
|
Phone string `json:"phone"`
|
|
Message string `json:"message"`
|
|
Attachments []string `json:"attachments"`
|
|
UserID string `json:"userId"`
|
|
}
|
|
|
|
type MessageStatusUpdate struct {
|
|
Status string `json:"status"`
|
|
ErrorCode string `json:"error_code,omitempty"`
|
|
ErrorMessage string `json:"error_message,omitempty"`
|
|
}
|
|
|
|
type UninstallWebhook struct {
|
|
LocationID string `json:"locationId"`
|
|
CompanyID string `json:"companyId"`
|
|
}
|
|
|
|
type InboundMessage struct {
|
|
Type string `json:"type"`
|
|
Message string `json:"message"`
|
|
Phone string `json:"phone"`
|
|
ConversationProviderID string `json:"conversationProviderId,omitempty"`
|
|
}
|
|
|
|
type InboundMessageResponse struct {
|
|
ConversationID string `json:"conversationId"`
|
|
MessageID string `json:"messageId"`
|
|
}
|