Bonjour,
j'ai fait faire une fonction pour whatapps pour la création de groupe, et je n'arrive pas à mettre les numéros que je vais chercher dans la base de données SQL alors que si je mets le numéro normalement, cela marche.
Voici la fonction :
public static function createGroup(string $groupName, array $participants): ?array
{
if (empty($groupName) || empty($participants)) {
return null;
}
// Supprime les doublons et ton propre numéro
$participants = array_unique($participants);
$participants = array_filter($participants, function ($number) {
return $number !== "33........"; // Remplace par self::$fromNumber si besoin
});
if (empty($participants)) {
return null; // Impossible de créer un groupe sans participants
}
try {
$url = self::$apiBaseUrl . '/group/create';
$data = [
'from_number' => self::$fromNumber,
'group' => [
'name' => $groupName,
'participants' => array_values($participants)
// 'participants' => array_map(function ($number) {
// return "+$number";
// }, $participants)
]
];
$response = self::sendCurlRequest($url, $data);
return $response;
} catch (\Throwable $th) {
echo $th->getMessage();
return null;
}
}
/***********************************/
--> si je le rentre comme ceci :
$participants = ['+33707070707', '+3370708080808']; ---> cela marche
en recuperant dans la base de donnée mes numéros, j'ai ceci
$groupe = "'+33707070707', '+3370708080808'";
si je fais ceci
$participants = [$groupe];
--> cela marche pas