{"id":19519152,"url":"https://github.com/cmdotcom/text-sdk-php","last_synced_at":"2025-04-06T02:07:17.768Z","repository":{"id":33537648,"uuid":"159319096","full_name":"cmdotcom/text-sdk-php","owner":"cmdotcom","description":"PHP SDK to send messages with CM.com","archived":false,"fork":false,"pushed_at":"2025-02-20T08:32:00.000Z","size":146,"stargazers_count":23,"open_issues_count":1,"forks_count":6,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-30T01:05:28.437Z","etag":null,"topics":["cm","imessage","line","messaging","push","rcs","sms","text","viber","wechat","whatsapp"],"latest_commit_sha":null,"homepage":"https://www.cm.com/communications-platform/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cmdotcom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-27T10:39:24.000Z","updated_at":"2025-03-10T11:19:24.000Z","dependencies_parsed_at":"2024-06-17T15:19:33.791Z","dependency_job_id":"73ce6163-533e-489b-b5df-ffe3c0f1e841","html_url":"https://github.com/cmdotcom/text-sdk-php","commit_stats":{"total_commits":41,"total_committers":10,"mean_commits":4.1,"dds":0.4390243902439024,"last_synced_commit":"21fdb819c29c3e14b0b217313838217861841784"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmdotcom%2Ftext-sdk-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmdotcom%2Ftext-sdk-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmdotcom%2Ftext-sdk-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmdotcom%2Ftext-sdk-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cmdotcom","download_url":"https://codeload.github.com/cmdotcom/text-sdk-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423512,"owners_count":20936626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cm","imessage","line","messaging","push","rcs","sms","text","viber","wechat","whatsapp"],"created_at":"2024-11-11T00:16:35.276Z","updated_at":"2025-04-06T02:07:17.748Z","avatar_url":"https://github.com/cmdotcom.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GitHub Workflow](https://github.com/cmdotcom/text-sdk-php/actions/workflows/main.yml/badge.svg)](https://github.com/cmdotcom/text-sdk-php/actions/workflows/main.yml)\n[![codecov](https://codecov.io/gh/cmdotcom/text-sdk-php/branch/master/graph/badge.svg)](https://codecov.io/gh/cmdotcom/text-sdk-php)\n[![Packagist](https://img.shields.io/packagist/dm/cmdotcom/text-sdk-php)](https://packagist.org/packages/cmdotcom/text-sdk-php)\n\n# CM Text SDK\nA software development kit to provide ways to interact with CM.com's Text service. API used:\n- [Business Messaging](https://developers.cm.com/messaging/docs)\n\n\n### Requirements\n\n- php 7.1 through 8.4 (inclusive)\n\n\n## Usage\n\n### Instantiate the client\nUsing your unique `ApiKey` (or product token) which authorizes you on the CM platform. Always keep this key secret!\n\nThe product token can be found in the [Channels](https://www.cm.com/app/channels) application on the platform, under the `Gateway` section.\n\n```php\n$client = new \\CMText\\TextClient('your-api-key');\n```\n\n### Send a message\nBy calling `SendMessage` and providing message text, sender name, recipient phone number(s) and a reference (optional).\n\n```php\n$result = $client-\u003eSendMessage('Message_Text', 'CM.com', [ 'Recipient_PhoneNumber' ], 'Your_Reference');\n```\n\n### Get the result\n`SendMessage` and `send` return an object of type `TextClientResult`, example:\n\n```json\n{\n  \"statusMessage\": \"Created 1 message(s)\",\n  \"statusCode\": 201,\n  \"details\": [\n    {\n      \"reference\": \"Example_Reference\",\n      \"status\": \"Accepted\",\n      \"to\": \"Example_PhoneNumber\",\n      \"parts\": 1,\n      \"details\": null\n    },\n    {\n      \"reference\": \"Example_Reference2\",\n      \"status\": \"Rejected\",\n      \"to\": \"Example_PhoneNumber2\",\n      \"parts\": 0,\n      \"details\": \"A body without content was found\"\n    }\n  ]\n}\n```\n\n### Status codes\nFor all possibly returned status codes, please reference the `TextClientStatusCodes` class.\n\n### Sending a rich message\nBy using the `Message` class it is possible to create messages with media for channels such as WhatsApp and RCS\n```php\n$client = new TextClient('your-api-key');\n$message = new Message('Message Text', 'Sender_name', ['Recipient_PhoneNumber']);\n$message\n    -\u003eWithChannels([Channels::WHATSAPP])\n    -\u003eWithHybridAppKey('your-secret-hybrid-app-key')\n    -\u003eWithRichMessage(\n        new MediaMessage(\n            'cm.com',\n            'https://avatars3.githubusercontent.com/u/8234794?s=200\u0026v=4',\n            'image/png'\n        )\n    )\n    -\u003eWithSuggestions([\n        new ReplySuggestion('Opt In', 'OK'),\n        new ReplySuggestion('Opt Out', 'STOP'),\n    ]);\n$result = $client-\u003esend( [$message] );\n```\n\n## Sending a WhatsApp template message\nBy using the `Message` class it is possible to create template messages. Please note that this is WhatsApp only and your template needs to be approved before sending.\nFor more info please check our documentation: https://www.cm.com/en-en/app/docs/api/business-messaging-api/1.0/index#whatsapp-template-message\n```php\n$client = new TextClient('your-api-key');\n$message = new Message('Message Text', 'Sender_name', ['Recipient_PhoneNumber']);\n$message\n    -\u003eWithChannels([Channels::WHATSAPP])\n    -\u003eWithTemplate(\n            new TemplateMessage(\n                new WhatsappTemplate(\n                    'namespace',\n                    'elementname',\n                    new Language('en'),\n                    [\n                        new ComponentBody([\n                            new ComponentParameterText('firstname')\n                        ])\n                    ]\n                )\n            )\n    );\n$result = $client-\u003esend( [$message] );\n```\n\n## Sending a rich WhatsApp template message\nIt is also possible to send a rich template with an image!\t\t\t\n\n```php\n$client = new TextClient('your-api-key');\n$message = new Message('Message Text', 'Sender_name', ['Recipient_PhoneNumber']);\n$message\n    -\u003eWithChannels([Channels::WHATSAPP])\n    -\u003eWithTemplate(\n        new TemplateMessage(\n            new WhatsappTemplate(\n                'template-name',\n                'the-namespace-of-template',\n                new Language('en'),\n                [\n                    new ComponentHeader([\n                        new ComponentParameterImage(\n                            new MediaContent(\n                                'image name',\n                                'https://image.location',\n                                'image/png'\n                            )\n                        )\n                    ]),\n                    new ComponentBody([\n                        new ComponentParameterText('firstname')\n                    ])\n                ]\n            )\n        )\n    );\n$result = $client-\u003esend( [$message] );\n```\n\n## Sending an Apple Pay Request\nIt is now possible to send an apple pay request only possible in Apple Business Chat\n\n```php\n$client = new TextClient('your-api-key');\n$message = new Message('Message Text', 'Sender_name', ['Recipient_PhoneNumber']);\n$message\n    -\u003eWithChannels([Channels::IMESSAGE])\n    -\u003eWithPayment(\n        new PaymentMessage(\n            new ApplePayConfiguration(\n                'merchant-name',\n                'product-description',\n                'unique-order-guid',\n                1,\n                'currency-code',\n                'recipient-email',\n                'recipient-country-code',\n                'language-country-code',\n                true,\n                true,\n                [\n                    new LineItem(\n                        'product-name',\n                        'final-or-pending',\n                        1\n                    )\n                ]\n            )\n        )\n    );\n$result = $client-\u003esend( [$message] );\n```\n\n## Sending WhatsApp interactive messages\nIt is now possible to send list messages and reply buttons without using templates\nonly supported in WhatsApp\n\n```php\n$client = new TextClient('your-api-key');\n$message = new Message('Message Text', 'Sender_name', ['Recipient_PhoneNumber']);\n$message\n    -\u003eWithChannels([Channels::WHATSAPP])\n    -\u003eWithRichMessage(\n        new WhatsAppInteractiveMessage(\n            new WhatsAppInteractiveContent(\n                WhatsAppInteractiveContentTypes::LIST,\n                new WhatsAppInteractiveHeader(\n                    WhatsAppInteractiveHeaderTypes::TEXT,\n                    'List message example'\n                ),\n                new WhatsAppInteractiveBody('checkout our list message demo'),\n                new WhatsAppInteractiveListAction(\n                    'Descriptive list title',\n                    [new WhatsAppInteractiveSection(\n                        'Select an option',\n                        [new WhatsAppInteractiveSectionRow(\n                            'unique title 1',\n                            rand(),\n                            'description text'\n                        ),new WhatsAppInteractiveSectionRow(\n                            'unique title 2',\n                            rand()\n                        )]\n                    )]\n                ),\n                new WhatsAppInteractiveFooter('footer text')\n            )\n        )\n    );\n$result = $client-\u003esend( [$message] );\n```\n\nOnly with Reply buttons you can send media like image,video or document\nsee following example.\n\n```php\n$client = new TextClient('your-api-key');\n$message = new Message('Message Text', 'Sender_name', ['Recipient_PhoneNumber']);\n$message\n    -\u003eWithChannels([Channels::WHATSAPP])\n    -\u003eWithRichMessage(\n        new WhatsAppInteractiveMessage(\n            new WhatsAppInteractiveContent(\n                WhatsAppInteractiveContentTypes::BUTTON,\n                new WhatsAppInteractiveHeader(\n                    WhatsAppInteractiveHeaderTypes::IMAGE,\n                    null,\n                    new MediaContent(\n                        'media name',\n                        'media.url',\n                        'mime/type'\n                    )\n                ),\n                new WhatsAppInteractiveBody('checkout our list message demo'),\n                new WhatsAppInteractiveButtonAction(\n                    [new WhatsAppInteractiveReplyButton(\n                        'button 1 reply-text',\n                        rand()\n                    ),new WhatsAppInteractiveReplyButton(\n                        'button 2 title',\n                        rand()\n                    )]\n                ),\n                new WhatsAppInteractiveFooter('footer text')\n            )\n        )\n    );\n$result = $client-\u003esend( [$message] );\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmdotcom%2Ftext-sdk-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmdotcom%2Ftext-sdk-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmdotcom%2Ftext-sdk-php/lists"}