33namespace Utopia \Messaging \Adapter \SMS ;
44
55use Utopia \Messaging \Adapter \SMS as SMSAdapter ;
6+ use Utopia \Messaging \Adapter \SMS \GEOSMS \CallingCode ;
67use Utopia \Messaging \Messages \SMS as SMSMessage ;
78use Utopia \Messaging \Response ;
89
@@ -23,7 +24,6 @@ class Fast2SMS extends SMSAdapter
2324 * @param string $apiKey Your Fast2SMS API authorization key
2425 * @param string $senderId Your 3-6 letter DLT approved Sender ID (e.g., "FSTSMS"). Required for DLT route
2526 * @param string $messageId Your DLT approved Message ID template. Required for DLT route
26- * @param string[] $variableValues Array of values for variables in DLT template message. Optional for DLT route
2727 * @param bool $useDLT Whether to use DLT route (true) or Quick SMS route (false)
2828 *
2929 * @see https://docs.fast2sms.com/#dlt-sms
@@ -33,7 +33,6 @@ public function __construct(
3333 private string $ apiKey ,
3434 private string $ senderId = '' ,
3535 private string $ messageId = '' ,
36- private array $ variableValues = [],
3736 private bool $ useDLT = false
3837 ) {
3938 }
@@ -66,7 +65,11 @@ public function getMaxMessagesPerRequest(): int
6665 */
6766 protected function process (SMSMessage $ message ): array
6867 {
69- $ numbers = implode (', ' , $ message ->getTo ());
68+ $ numbers = array_map (
69+ fn ($ number ) => $ this ->removeCountryCode ($ number ),
70+ $ message ->getTo ()
71+ );
72+ $ numbers = implode (', ' , $ numbers );
7073
7174 $ payload = [
7275 'numbers ' => $ numbers ,
@@ -77,10 +80,7 @@ protected function process(SMSMessage $message): array
7780 $ payload ['route ' ] = 'dlt ' ;
7881 $ payload ['sender_id ' ] = $ this ->senderId ;
7982 $ payload ['message ' ] = $ this ->messageId ;
80-
81- if (!empty ($ this ->variableValues )) {
82- $ payload ['variables_values ' ] = implode ('| ' , $ this ->variableValues );
83- }
83+ $ payload ['variables_values ' ] = $ message ->getContent ();
8484 } else {
8585 $ payload ['route ' ] = 'q ' ;
8686 $ payload ['message ' ] = $ message ->getContent ();
@@ -113,4 +113,24 @@ protected function process(SMSMessage $message): array
113113
114114 return $ response ->toArray ();
115115 }
116+
117+ /**
118+ * Removes country code from a phone number
119+ * Fast2SMS expects Indian phone numbers without the country code
120+ *
121+ * @param string $number Phone number with potential country code
122+ * @return string Phone number without country code
123+ */
124+ private function removeCountryCode (string $ number ): string
125+ {
126+ // Remove any non-digit characters
127+ $ digits = preg_replace ('/[^0-9]/ ' , '' , $ number );
128+
129+ $ code = CallingCode::fromPhoneNumber ($ number );
130+ if ($ code !== null ) {
131+ return substr ($ digits , strlen ($ code ));
132+ }
133+
134+ return $ digits ;
135+ }
116136}
0 commit comments