{"id":26450999,"url":"https://github.com/syniverse/messaging-php","last_synced_at":"2025-03-18T16:07:07.161Z","repository":{"id":37547409,"uuid":"71072679","full_name":"Syniverse/Messaging-PHP","owner":"Syniverse","description":"PHP SDK for SCG Messaging APIs","archived":false,"fork":false,"pushed_at":"2022-06-21T17:42:38.000Z","size":81,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":11,"default_branch":"master","last_synced_at":"2023-02-27T15:01:45.956Z","etag":null,"topics":["mms","php","scg","senderid","shortcode","sms-api","voice"],"latest_commit_sha":null,"homepage":"https://syniverse.github.io/Messaging-PHP/","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/Syniverse.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}},"created_at":"2016-10-16T19:36:25.000Z","updated_at":"2020-05-13T00:15:47.000Z","dependencies_parsed_at":"2022-08-18T03:01:36.945Z","dependency_job_id":null,"html_url":"https://github.com/Syniverse/Messaging-PHP","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Syniverse%2FMessaging-PHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Syniverse%2FMessaging-PHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Syniverse%2FMessaging-PHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Syniverse%2FMessaging-PHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Syniverse","download_url":"https://codeload.github.com/Syniverse/Messaging-PHP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244257251,"owners_count":20424131,"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":["mms","php","scg","senderid","shortcode","sms-api","voice"],"created_at":"2025-03-18T16:07:06.416Z","updated_at":"2025-03-18T16:07:07.152Z","avatar_url":"https://github.com/Syniverse.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP SDK for SCG Messaging APIs\n\nThis is the PHP version of the SCG API. \nThe SCG APIs provides access to communication channels using SMS, MMS, \nPush Notification, OTT messaging and Voice. \n\nWe have prepared a thin PHP wrapper over the REST API for\nthese services. \n\nThe PHP SDK hides some of the REST API's constraints, like\nlists being returned in logical pages of _n_ records. With the\nPHP SDK, the list method returns a generator that works with *foreach()*.\n\nPlease register for a free account at https://developer.syniverse.com to get your API keys.\n\n## External dependencies\nDependencies can be installed with [composer](https://getcomposer.org/).\n\n- [guzzle](https://github.com/guzzle/guzzle)\n\nTo install the dependencies for ths project:\n```sh\n$ composer install\n$ composer dump-autoload\n```\n\n## How to use the SDK\nThe PHP SDK implements a thin wrapper classes over the \ndifferent Messaging API resources. Using these resource\nclasses, you can create, get, update, list, replace and delete\nobjects.\n\n# Some examples\n\n## List all contacts\n```php\nfunction list_contacts(array $options)\n{\n    $session = new ScgApi\\Session($options);\n    $res =  new ScgApi\\ContactResource($session);\n\n    foreach($res-\u003elist() as $c) {\n        echo \"Contact ${c['id']} ${c['first_name']} mdn: ${c['primary_mdn']}\" \n            . PHP_EOL;\n    }\n}\n```\nThis program will output something like:\n```\nContact 4AOXpg8dlXRCMXlWDUch73 Alice mdn: 155560000002\nContact vsXgkqhUW4eIwMColyevn7 Bob mdn: 1555898230057\n```\n[Full example](examples/list_contacts.php)\n\n\n## Create and update a contact\n\n```php\nfunction update_contact(string $mdn, array $options)\n{\n    $session = new ScgApi\\Session($options);\n    $res =  new ScgApi\\ContactResource($session);\n\n    $contactId = $res-\u003ecreate([\n        'first_name' =\u003e'John',\n        'last_name' =\u003e 'Doe',\n        'primary_mdn' =\u003e $mdn\n        ])['id'];\n\n    $contact = $res-\u003eget($contactId);\n\n    $res-\u003eupdate($contactId, [\n        'last_name'=\u003e'Anderson',\n        'version_number' =\u003e $contact['version_number']\n        ]);\n\n    $contact = $res-\u003eget($contactId);\n\n    echo \"John Doe changed name to ${contact['first_name']} ${contact['last_name']}\";\n    echo PHP_EOL;\n}\n\n```\nYou can create an object by calling *create* with a associate array\nof the data values for the object you create.\n\nIn this example, please notice the *version_number* field that we copy from\nthe received data to the *update* argument. The server use optimistic\nlocking to safeguard against inconsistent updates of the data. In case\nsomeone else updated the contact in the time window between your *get*\nand *update* calls, the update will fail. In that case you must retry the\noperation - first getting the data, with the new version, and then \nretrying the update with your changes - and the new *version_number*.\nThis pattern applies for all objects that can be updated.\n\nThe example will output:\n```\nJohn Doe changed name to John Anderson\n```\n[Full example](examples/update_contact.php)\n\n## Error handling\nErrors are reported trough exceptions. Please see the \nPHP [composer](https://getcomposer.org/) library\nfor reference.\n\n# Some more examples\n\n## Sending a SMS to a Mobile number\n\n```php\nfunction send_sms(string $senderid, string $mdn, string $content, array $options)\n{\n   $session = new ScgApi\\Session($options);\n    $res = new ScgApi\\MessageRequestResource($session);\n    $request_id = $res-\u003ecreate(\n        ['from' =\u003e \"sender_id:${senderid}\", \n        'to' =\u003e[$mdn], \n        'body' =\u003e $content\n        ])['id'];\n\n    echo \"Created message request ${request_id}\" . PHP_EOL;\n}\n```\n\n[Full example](examples/send_sms.php)\n\n## Sending a Message to a Contact\n\nThis works as above, except for the *to* field in *create*.\n```php\n    $request_id = $res-\u003ecreate(\n        ['from' =\u003e \"sender_id:${senderid}\", \n        'to' =\u003e['contact:' + contact_id], \n        'body' =\u003e $content\n        ])['id'];\n\n```\n\n## Sending a Message to a Contact Group\n\nHere we will create two new contacts, a new group, assign the contacts\nto the group, and then send a message to the group.\n\n```php\nfunction send_sms(string $senderid, string $mdn1, string $mdn2, string $content, \n    array $options)\n{\n    $session = new ScgApi\\Session($options);\n\n    // Create a group\n    $groupRes = new \\ScgApi\\ContactGroupResource($session);\n    $friendsId = $groupRes-\u003ecreate(['name' =\u003e 'friends'])['id'];\n\n    // Create contacts\n    $contactRes = new \\ScgApi\\ContactResource($session);\n    $alice = $contactRes-\u003eCreate([\n            'first_name'=\u003e'Alice', \n            'primary_mdn'=\u003e$mdn1\n            ])['id'];\n    $bob = $contactRes-\u003eCreate([\n            'first_name'=\u003e'Bob', \n            'primary_mdn'=\u003e$mdn2\n            ])['id'];\n\n    // Add the contacts to our group\n    $groupRes-\u003eaddContacts($friendsId, [$alice, $bob]);\n\n    // Send an sms to our new friends\n    $mrqRes = new ScgApi\\MessageRequestResource($session);\n    $requestId = $mrqRes-\u003ecreate([\n        'from' =\u003e \"sender_id:${senderid}\",\n        'to' =\u003e [\"group:${friendsId}\"],\n        'body' =\u003e $content])['id'];\n\n    echo \"Created message request ${requestId}\" . PHP_EOL;\n}\n\n```\n[Full example](examples/send_sms_to_grp.php)\n\n## Sending a MMS with an attachment\n\n```php\nfunction send_mms(string $senderid, string $mdn, string $content,\n                  string $attachment, array $options)\n{\n    $session = new ScgApi\\Session($options);\n\n    $att_res = new ScgApi\\AttachmentResource($session);\n    $att_id = $att_res-\u003ecreate(\n        ['name' =\u003e 'test_upload', 'type' =\u003e 'image/jpeg',\n        'filename' =\u003e 'cutecat.jpg'])['id'];\n\n    echo \"Created attachment ${att_id}. Will now upload.\" . PHP_EOL;\n\n    // $attachment is the path to a file to upload\n    $att_res-\u003eupload($att_id, $attachment);\n\n    $mrq_res = new ScgApi\\MessageRequestResource($session);\n\n    $request_id = $mrq_res-\u003ecreate(\n        ['from' =\u003e \"sender_id:${senderid}\",\n        'to' =\u003e[$mdn],\n        'attachments' =\u003e [$att_id],\n        'body' =\u003e $content])['id'];\n\n    echo \"Created message request ${request_id}\" . PHP_EOL;\n}\n```\n\n[Full example](examples/send_mms.rb)\n\n## Checking the state of a Message Request\n\n```php\nfunction check_state(string $mrqId, array $options)\n{\n    $session = new ScgApi\\Session($options);\n    $res = new ScgApi\\MessageRequestResource($session);\n    \n    $mrq = $res-\u003eget($mrqId);\n    print_r($mrq);\n\n    foreach($res-\u003elistMessages($mrqId) as $m) \n    {\n        print_r($m);\n    }\n}\n```\n\nThe example below may output something like:\n```\nArray\n(\n    [application_id] =\u003e 888\n    [company_id] =\u003e 12121\n    [created_date] =\u003e 1501586862472\n    [last_updated_date] =\u003e 1501586864444\n    [version_number] =\u003e 2\n    [id] =\u003e ryfKsD5F5z3VBE2iCs5C8\n    [from] =\u003e sender_id:OgX4Y8AuTzO8VExVGphKkg\n    [to] =\u003e Array\n        (\n            [0] =\u003e +155512345678\n        )\n\n    [body] =\u003e Hello world\n    [state] =\u003e COMPLETED\n    [recipient_count] =\u003e 1\n    [sent_count] =\u003e 0\n    [delivered_count] =\u003e 0\n    [media_requested_count] =\u003e 0\n    [read_count] =\u003e 0\n    [click_thru_count] =\u003e 0\n    [converted_count] =\u003e 0\n    [canceled_count] =\u003e 0\n    [failed_count] =\u003e 0\n    [sender_id_sort_criteria] =\u003e Array\n        (\n        )\n\n    [contact_delivery_address_priority] =\u003e Array\n        (\n        )\n\n)\nArray\n(\n    [application_id] =\u003e 888\n    [company_id] =\u003e 12121\n    [created_date] =\u003e 1501586864248\n    [last_updated_date] =\u003e 1501586866275\n    [version_number] =\u003e 2\n    [id] =\u003e jx6bQRK2jEJ0emtj3B0Yz3\n    [message_request_id] =\u003e ryfKsD5F5z3VBE2iCs5C8\n    [direction] =\u003e MT\n    [customer_sender_id] =\u003e OgX4Y8AuTzO8VExVGphKkg\n    [from_address] =\u003e 2341026195\n    [to_address] =\u003e +3598957000514\n    [state] =\u003e SENT\n    [body] =\u003e Hello world\n    [sent_date] =\u003e 1501586864543\n    [type] =\u003e SMS\n    [destination_country] =\u003e BGR\n    [price] =\u003e 0.0212\n    [sender_id_alias] =\u003e OgX4Y8AuTzO8VExVGphKkg\n    [fragments_info] =\u003e Array\n        (\n            [0] =\u003e Array\n                (\n                    [fragment_id] =\u003e 6KMxtsP0ndjgWT5AFxPH61\n                    [fragment_state] =\u003e SENT\n                    [charge] =\u003e 0.0212\n                    [external_id] =\u003e 5150092268783864\n                    [delivery_report_reference] =\u003e 6KMxtsP0ndjgWT5AFxPH61\n                )\n\n        )\n\n    [consent_requirement] =\u003e NONE\n)\n\n```\n\n[Full example](examples/check_message_request_state.php)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyniverse%2Fmessaging-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyniverse%2Fmessaging-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyniverse%2Fmessaging-php/lists"}