THE PROBLEM
Someone may reply to an SMS message with one or more images, as well as text content. The images are auto-uploaded to https://clicksend-api-downloads.s3.ap-southeast-2.amazonaws.com and the urls are prepended to the body of the reply. The resulting reply is rendered properly in the ClickSend website - see example below (REPLY ON CLICKSEND WEBSITE). Unfortunately, something goes wrong when the reply is forwarded to an url.
It appears that the reply body is split up - perhaps in error - with the url query parameters becoming keys in the associative map sent to the url. See an example below (RECEIVED REPLY SENT TO URL). Note that parameters such as "X-Amz-Algorithm" and "X-Amz-Expires" become keys in the reply received. Also, note that the value for "X-Amz-Signature" in the reply contains the text reply.
POTENTIAL SOLUTION A: Simply send the text reply in the ClickSend website without breaking it up
If the text reply in the ClickSend is sent as-is to the url, then this can be easily parsed (see PHP CODE TO EXTRACT URLS AND TEXT). The code works if there is no url in the message. It would be up to the receiver to use the urls to download the images and manage them according to their system.
POTENTIAL SOLUTION B: Pre-process a reply with urls
ClickSend could extract the urls and place them into a dedicated key in the content sent to the url. This key could be downloadurls which will be a list of the urls. The body sent to the url would then not include the urls.
This solution clearly requires extra work by ClickSend. Given that the vast majority of SMS replies do not contain downloads, ClickSend could push the processing work to the receiver instead, which is Potential Solution A.
========= START: REPLY ON CLICKSEND WEBSITE
========= END: REPLY ON CLICKSEND WEBSITE
========= START: RECEIVED REPLY SENT TO URL (SOME FIELDS REMOVED FOR PRIVACY)
{"body":"https:\/\/clicksend-api-downloads.s3.ap-southeast-2.amazonaws.com\/_private\/79BDD60F-15F7-4392-982F-FCBF8BCD25A03.jpg?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD","X-Amz-Algorithm":"AWS4-HMAC-SHA256","X-Amz-Credential":"AKIAWKMIV4OKATYVXFML\/20250924\/ap-southeast-2\/s3\/aws4_request","X-Amz-Date":"20250924T002156Z","X-Amz-SignedHeaders":"host","X-Amz-Expires":"600000","X-Amz-Signature":"6d9eea1617893baa7f4f6f879052d9edc7c30a2a1c7773258636af44fd0fc1c6\nHere you go April.","message":"https:\/\/clicksend-api-downloads.s3.ap-southeast-2.amazonaws.com\/_private\/79BDD60F-15F7-4392-982F-FCBF8BCD25A03.jpg?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD","originalmessageid":"1F098D92-33C2-626A-8EC3-8F8CED5AC358","originalmessage":"Hi Joe,\n\nThis is April ...\n\nOn reply, standard SMS charges may apply.\nTo opt out of text messages, reply STOP","message_id":"1F098DC7-AB68-6730-9E7E-83836CC64126"}
========= END: RECEIVED REPLY SENT TO URL
========= START: PHP CODE TO EXTRACT URLS AND TEXT
// Extract URLs using regex
preg_match_all('/https:\/\/[^\s]+/', $input, $matches);
$urls = $matches[0];
// Remove all URLs to get remaining text
$text = preg_replace('/https:\/\/[^\s]+\s*/', '', $input);
$text = trim($text);
// Output results
echo "URLs found: " . count($urls) . "\n";
foreach ($urls as $i => $url) {
echo "URL: " . $url . "\n";
}
echo "\nText: " . $text . "\n";
========= END: PHP CODE TO EXTRACT URLS AND TEXT