Skip to main content

Decode URL

Decodes a URL and retrieves Open Graph (OG) metadata, such as title, image, description, and the URL itself. This function helps in fetching rich previews of URLs by extracting their metadata.

Steps to decode a URL

  1. Create a DecodeUrlRequest object using the builder pattern.
  2. Call the decodeUrl() function using the instance of ConversationClient, passing the request object and an optional response handler.
  3. Process the response LMResponse<DecodeUrlResponse> to handle the decoded metadata or any errors.
let request = DecodeUrlRequest.builder()
.url("https://example.com")
.build()

LMChatClient.shared.decodeUrl(request: request) { response in
if let result = response?.data {
// Handle success
} else if let error = response?.error {
// Handle error
print("Error decoding URL: \(error.localizedDescription)")
}
}

Models

DecodeUrlRequest

VARIABLETYPEDESCRIPTIONOPTIONAL
urlStringThe URL to be decoded

DecodeUrlResponse

VARIABLETYPEDESCRIPTIONOPTIONAL
ogTagsLinkOGTagmetadata retrieved from the URL