Back

[CLOSED] Implement support for CM in the Utopia PHP messaging library

  • 1
  • Web
vividh003
13 Oct, 2023, 19:39

This is an issue I have been facing with fixing this github issue- https://github.com/appwrite/appwrite/issues/6386 . My doubt is I am not able to find CM adapter information. Could anyone please guide me regarding this. I also wanted to know how can I test this after creating the adapter.

TL;DR
The user wants to implement support for CM in the Utopia PHP messaging library. They have written a code snippet for the CM adapter. They have also asked for guidance on testing and mentioned a related GitHub issue. A solution is not provided in the thread.
Drake
13 Oct, 2023, 19:42

the requirements for picking up this issue was:

Experience with CM.

Drake
13 Oct, 2023, 19:48

Have you read through their docs?

vividh003
14 Oct, 2023, 08:51

I've had some experience with PHP and was planning to learn to integrate CM along the way via solving this issue.

TypeScript
<?php

namespace Utopia\Messaging\Adapters\SMS;

use Utopia\Messaging\Adapters\SMS as SMSAdapter;
use Utopia\Messaging\Messages\SMS;

class CM extends SMSAdapter
{
    /**
     * @param string $apiKey CM API Key
     */
    public function __construct(
        private string $apiKey
    ) {
    }

    public function getName(): string
    {
        return 'CM';
    }

    public function getMaxMessagesPerRequest(): int
    {
        return 1;
    }

    /**
     * {@inheritdoc}
     *
     * @throws \Exception
     */
    protected function process(SMS $message): string
    {
        return $this->request(
            method: 'POST',
            url: 'https://api.cmtelecom.com/v1.0/message',
            headers: [
                'Content-Type: application/json',
                'Authorization: Bearer ' . $this->apiKey,
            ],
            body: json_encode([
                'from' => $message->getFrom(),
                'to' => $message->getTo()[0],
                'body' => $message->getContent(),
            ]),
        );
    }
}

This is what I have come up with

Drake
14 Oct, 2023, 14:36

Make sure to test it and add any reference material to the PR (or as comments in the code)

vividh003
25 Oct, 2023, 17:49
vividh003
25 Oct, 2023, 17:49

Could you please review this once

Drake
25 Oct, 2023, 17:57

Linting failed. Please also add screenshots of successful tests

vividh003
1 Nov, 2023, 10:36

I haven't tested it actually. How can I pass the Linting tests?

Haimantika
1 Nov, 2023, 11:44

We have the linting information in our contributing guide here

vividh003
1 Nov, 2023, 12:03

Okay thanks, I’ll look into it

Haimantika
1 Nov, 2023, 19:17

Let us know if we can close this thread for now. You can always text again, if you have more doubts 🙂

vividh003
2 Nov, 2023, 16:57

Sure

Haimantika
2 Nov, 2023, 17:51

[CLOSED] Implement support for CM in the Utopia PHP messaging library

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more