php-rest-api icon indicating copy to clipboard operation
php-rest-api copied to clipboard

Fatal error: Uncaught Error: Class "MessageBirdObjectsConversationContent" not found in F:\xampp\htdocs\habraacdb\api\index.php:7 Stack trace: #0 {main} thrown in F:\xampp\htdocs\habraacdb\api\index.php on line 7

Open siyaadguul opened this issue 4 years ago • 17 comments

when i tried to send Whatsapp message from my php

siyaadguul avatar Dec 21 '21 05:12 siyaadguul

Hi @siyaadguul .

Can you please provide some details and maybe a short code sample on how you're trying to do the call ? From the error stack above it looks more like an issue loading the class rather than an implementation issue.

Thanks

CoolGoose avatar Dec 22 '21 08:12 CoolGoose

text = 'Hello!'; $message = new MessageBirdObjectsConversationMessage(); $message->content = $content; $message->to = '252615302173'; $message->type = 'text'; $message->channelId = 'chan_id'; try { $conversation = $MessageBird->conversations->start($message); var_dump($conversation); } catch (Exception $e) { echo sprintf("%s: %s", get_class($e), $e->getMessage()); } ?>

siyaadguul avatar Dec 22 '21 08:12 siyaadguul

i am trying like this and i want to send message to my customer usign php

siyaadguul avatar Dec 22 '21 08:12 siyaadguul

Hey, you can check the examples folder for some code sample, but for starting a conversation it should be like: We do use namespaces for the class.

$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.

$content = new \MessageBird\Objects\Conversation\Content();
$content->text = 'Hello world';

$message = new \MessageBird\Objects\Conversation\Message();
$message->channelId = 'CHANNEL_ID';
$message->content = $content;
$message->to = 'RECIPIENT'; // Channel-specific, e.g. MSISDN for SMS.
$message->type = 'text';

try {
    $conversation = $messageBird->conversations->start($message);

    var_dump($conversation);
} catch (\Exception $e) {
    echo sprintf("%s: %s", get_class($e), $e->getMessage());
}

CoolGoose avatar Dec 22 '21 08:12 CoolGoose

  • [ ] thank you sir

siyaadguul avatar Dec 22 '21 09:12 siyaadguul

it's now working. But the message get failed to send

siyaadguul avatar Dec 22 '21 09:12 siyaadguul

If the SDK call didn't error out, it should get into MessageBird's system so I would recommend contacting MessageBird's support with details about channelId/ recipient so we don't expose sensitive information on public boards.

CoolGoose avatar Dec 22 '21 09:12 CoolGoose

when i try to initiate new conversation i am gets error(MessageBird\Exceptions\AuthenticateException: Got error response from the server: Recipient not authorised)

siyaadguul avatar Dec 23 '21 07:12 siyaadguul

@siyaadguul that is the authentication error in case you didn't send the correct YOUR_ACCESS_KEY. For that purpose, I would also advise contacting MessageBird internally so we don't leak information.

CoolGoose avatar Dec 23 '21 08:12 CoolGoose

Okey Thank you i fixed it but the only condition that i am facing now is when i execute and send a message it gets done but when i tried to send with another contact it get undone and no messages reaches to the target example of my code require('autoload.php');

// Set your own API access key here. // Create a client with WhatsApp sandbox enabled. $messageBird = new \MessageBird\Client('key');

// Use WhatsApp sandbox channel as normal.

$content = new \MessageBird\Objects\Conversation\Content(); $content->text = 'Hello world';

$message = new \MessageBird\Objects\Conversation\SendMessage(); $message->from = 'chid'; $message->content = $content; $message->to = '252616429555'; // Channel-specific, e.g. MSISDN for SMS. $message->type = 'text';

try { $conversation = $messageBird->conversationSend->send($message);

var_dump($conversation);

} catch (Exception $e) { echo sprintf("%s: %s", get_class($e), $e->getMessage()); }

siyaadguul avatar Dec 23 '21 08:12 siyaadguul

i want to send a message to my every customer who reaches my website or did registred in my system example so send updates,notices,offers,bills and so on

siyaadguul avatar Dec 23 '21 08:12 siyaadguul

If you don't need 2 way communication and you just want to notify your customers I'd recommend using the simpler send message functionality.

When you say you want to send from another contact, are you doing a for/foreach for multiple contacts, or are you just calling this same endpoint a couple of times?

$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.

$message             = new \MessageBird\Objects\Message();
$message->originator = 'YourBrand';
$message->recipients = [31612345678];
$message->body       = 'This is a test message.';

try {
    $messageResult = $messageBird->messages->create($message);
    var_dump($messageResult);
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
    // That means that your accessKey is unknown
    echo 'wrong login';
} catch (\MessageBird\Exceptions\BalanceException $e) {
    // That means that you are out of credits, so do something about it.
    echo 'no balance';
} catch (\Exception $e) {
    echo $e->getMessage();
}

CoolGoose avatar Dec 23 '21 09:12 CoolGoose

i want to send whatsapp messages to my customers not messages first. and i think this code is about sms second i want to call if contact is about 1 contact if its more than one contact or customer i have to use looping like for or while

siyaadguul avatar Dec 23 '21 09:12 siyaadguul

I want customers whether I have spoken to them on whatsapp or not to get the message across

siyaadguul avatar Dec 23 '21 13:12 siyaadguul

Understood. I'll do a test run locally also and get back to you. There's no reason why another call shouldn't work for you. Thanks

CoolGoose avatar Dec 23 '21 14:12 CoolGoose

okey

siyaadguul avatar Dec 23 '21 15:12 siyaadguul

Understood. I'll do a test run locally also and get back to you. There's no reason why another call shouldn't work for you. Thanks

hi Sir,

siyaadguul avatar Dec 25 '21 07:12 siyaadguul

Closing this to due to inactivity.

dennisvdvliet avatar Jan 13 '23 07:01 dennisvdvliet