Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Rayray's avatar

Africans Talking SDK php Laravel getDigits($options) ERROR:::: "message": "Array to string conversion",

Am trying to build a call center with Africans Talking SDK php Laravel but am getting but an gettings an errot when it comes to getdigits($options) ERROR:::: "message": "Array to string conversion",

        $welcome = 'https://call_center2/welcome_note.mp3';
        $categoryselect = 'https:/call_center2/helpcategoryselect.mp3';
        $noresponse = 'https://call_center2/noresponse.mp3';
        $callbackurl = 'https:/api/call_center/helpcategory/'.$user->id;


        $options = [
            'numDigits' => 2,
            'timeout' => 45,
            'finishOnKey' => '#',
            'callbackUrl' => $callbackurl ,
        ];

  
        $voiceActions = $this->voice->messageBuilder();
        $xmlresponse = $voiceActions->play($welcome)->play($categoryselect)->getDigits($options)->play($noresponse)->build();
        return $xmlresponse;
0 likes
14 replies
Sinnbeck's avatar

Is it a laravel package you are using or the direct package? Link?

Sinnbeck's avatar

I also assume that the error message isn't from your code, as it has lowercase "getdigits" while yours has uppercase D

Sinnbeck's avatar

@Rayray Ok so not a laravel package but just a plain composer package. I assume you are hiding some code, as you dont set $this->voice anywhere?

Rayray's avatar

@Sinnbeck YES PLEASE

				public function __construct(Request $request){
       					 $this->username = "sandbox";
        					$this->afriapikey   = "MYAPIKEY";
        					$this->AT = new AfricasTalking($this->username, $this->afriapikey);
        					$this->voice    = $this->AT->voice();
        					$this->sessionId = $request['sessionId'];
        					$this->isActive  = $request['isActive'];
        					$this->callerNumber = $request['callerNumber'];
        					$this->phone = substr($this->callerNumber, 3);
					}
Rayray's avatar

when I remove getdigits() from the $xmlresponse , i get no error

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

I am also curious why it does not mention that "text" is required

https://github.com/AfricasTalkingLtd/africastalking-php/blob/e67abc98af2a2cdc586105abd84ac570306047d3/src/Voice.php#L203

Maybe you need to set it before the digitts?

$voiceActions = $this->voice->messageBuilder();
        $xmlresponse = $voiceActions->play($welcome)->play($categoryselect)->say('foobar')->getDigits($options)->play($noresponse)->build();
        return $xmlresponse;

or pass it in

$options = [
            'text' => 'foobar',
            'numDigits' => 2,
            'timeout' => 45,
            'finishOnKey' => '#',
            'callbackUrl' => $callbackurl ,
        ];
1 like
Sinnbeck's avatar

@Rayray Are you able to share it from flare (the error page has a share button). Remember to check that it does not have your api credentials there.

Rayray's avatar

@Sinnbeck Actually these guys forgot to make text nullable, therefore you have to pass it as a null

It worked like this. Thanks alot

$voiceActions = $this->voice->messageBuilder();

        $options = [
            'text' => '',
            'url'  => $categoryselect,
            'numDigits' => 2,
            'timeout' => 45,
            'finishOnKey' => '#',
            'callbackUrl' => $callbackurl,
        ];

        $xmlresponse = $voiceActions->play($welcome)->getDigits($options)->play($noresponse)->build();
        return $xmlresponse;

Please or to participate in this conversation.