diff --git a/.env-example b/.env-example index 8360d92..e43e6ba 100644 --- a/.env-example +++ b/.env-example @@ -31,4 +31,28 @@ REQUEST_ID= WORKFLOW_ID=4 RECIPIENT_NUMBER= PAYEE_NAME= -AMOUNT= \ No newline at end of file +AMOUNT= + +# Messages API examples +FB_SENDER_ID= +FB_RECIPIENT_ID= +VIBER_SERVICE_MESSAGE_ID= +WHATSAPP_NUMBER= +WHATSAPP_TEMPLATE_NAMESPACE= +WHATSAPP_TEMPLATE_NAME= +WHATSAPP_AUTH_TEMPLATE_NAME= +WHATSAPP_TEMPLATE_REPLACEMENT_TEXT= +IMAGE_URL= +IMAGE_CAPTION= +FILE_URL= +FILE_CAPTION= +AUDIO_URL= +VIDEO_URL= + +## For Messages Sandbox +MESSAGES_SANDBOX_URL= +MESSAGES_SANDBOX_WHATSAPP_NUMBER= +MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER= +MESSAGES_SANDBOX_FB_ID= +MESSAGES_SANDBOX_ALLOW_LISTED_FB_RECIPIENT_ID= +MESSAGES_SANDBOX_VIBER_SERVICE_ID= diff --git a/.gitignore b/.gitignore index 98b9c68..2cdee93 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,14 @@ private.key .env composer.lock .DS_Store +/.idea/codeception.xml +/.idea/deployment.xml +/img.png +/.idea/material_theme_project_new.xml +/.idea/modules.xml +/.idea/php.xml +/.idea/phpspec.xml +/.idea/phpunit.xml +/.idea/symfony2.xml +/.idea/vcs.xml +/.idea/vonage-php-code-snippets.iml diff --git a/LICENSE.md b/LICENSE.md index d046301..29a9fad 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,21 +1,202 @@ -The MIT License (MIT) - -Copyright (c) 2019 Nexmo Community - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md index a7dae11..f9441c2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Vonage APIs Quickstart Examples for PHP -Nexmo is now known as Vonage +Vonage logo The purpose of the quickstart guide is to provide simple PHP examples focused on one goal. For example, sending an SMS, receiving an SMS via an incoming SMS webhook or making a Text to Speech call. @@ -8,7 +8,7 @@ Quickstarts also available for [Java](https://github.com/nexmo/nexmo-java-code-s ## Setup -These code samples are meant to be used for [https://developer.nexmo.com/](https://developer.nexmo.com/), and are structured in such a way as to be used for internal testing. Developers are free to use these code snippets as a reference, but these may require changes to be worked into your specific application. We recommend checking out the [Vonage Developer Website](https://developer.nexmo.com/), which displays these code snippets in a more copy/paste fashion. +These code samples are meant to be used for [https://developer.vonage.com/](https://developer.vonage.com/), and are structured in such a way as to be used for internal testing. Developers are free to use these code snippets as a reference, but these may require changes to be worked into your specific application. We recommend checking out the [Vonage Developer Website](https://developer.vonage.com/), which displays these code snippets in a more copy/paste fashion. If you would like to run these examples yourself, you will need to do the following: @@ -22,10 +22,10 @@ Larger or more complex snippets may include their own `composer.json` file and h ## Configure with Your Vonage API Keys -To use this sample you will first need a [Vonage account](https://dashboard.nexmo.com/sign-up). Once you have your own API credentials, rename +To use this sample you will first need a [Vonage account](https://dashboard.vonage.com/sign-up). Once you have your own API credentials, rename the `.env-example` file to `.env` and set the values as required. -For some of the examples, you will need to [buy a number](https://dashboard.nexmo.com/buy-numbers). +For some of the examples, you will need to [buy a number](https://dashboard.vonage.com/buy-numbers). ## Request More Examples @@ -33,6 +33,5 @@ Please [raise an issue](/../../issues/) to request an example that isn't present ## Licenses -- The sample code in this repo is licensed under [MIT](LICENSE.md) +- The sample code in this repo is licensed under [Apache2](LICENSE.md) - ​ diff --git a/composer.json b/composer.json index 030432a..63d7b38 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,12 @@ { "require": { - "vonage/client": "^2.3", + "vonage/client": "^4.0", "vlucas/phpdotenv": "^2.5", - "lcobucci/jwt": "^4.0" + "lcobucci/jwt": "^4.0", + "ext-json": "*" + } + , + "require-dev": { + "roave/security-advisories": "dev-latest" } } diff --git a/conversation/conversation/create-conversation.php b/conversation/conversation/create-conversation.php new file mode 100644 index 0000000..a578628 --- /dev/null +++ b/conversation/conversation/create-conversation.php @@ -0,0 +1,17 @@ +conversation()->createConversation($createConversationRequest); \ No newline at end of file diff --git a/conversation/conversation/delete-conversation.php b/conversation/conversation/delete-conversation.php new file mode 100644 index 0000000..b07f57e --- /dev/null +++ b/conversation/conversation/delete-conversation.php @@ -0,0 +1,15 @@ +conversation()->deleteConversationById(CONVERSATION_ID); \ No newline at end of file diff --git a/conversation/conversation/get-conversation.php b/conversation/conversation/get-conversation.php new file mode 100644 index 0000000..eaa1b93 --- /dev/null +++ b/conversation/conversation/get-conversation.php @@ -0,0 +1,15 @@ +conversation()->getConversationById(CONVERSATION_ID); \ No newline at end of file diff --git a/conversation/conversation/list-conversations.php b/conversation/conversation/list-conversations.php new file mode 100644 index 0000000..f8b50c2 --- /dev/null +++ b/conversation/conversation/list-conversations.php @@ -0,0 +1,15 @@ +conversation()->listConversations(); \ No newline at end of file diff --git a/conversation/conversation/update-conversations.php b/conversation/conversation/update-conversations.php new file mode 100644 index 0000000..467ac15 --- /dev/null +++ b/conversation/conversation/update-conversations.php @@ -0,0 +1,21 @@ + CONV_NEW_NAME, + 'display_name' => CONV_NEW_NAME +]); + +$client->conversation()->updateConversationById(CONVERSATION_ID, $updateConversationRequest); \ No newline at end of file diff --git a/conversation/event/create-custom-event.php b/conversation/event/create-custom-event.php new file mode 100644 index 0000000..4bc6439 --- /dev/null +++ b/conversation/event/create-custom-event.php @@ -0,0 +1,25 @@ + 'data' + ] +); + +$client->conversation()->createEvent($eventRequest); \ No newline at end of file diff --git a/conversation/event/create-event.php b/conversation/event/create-event.php new file mode 100644 index 0000000..3b017cf --- /dev/null +++ b/conversation/event/create-event.php @@ -0,0 +1,22 @@ +conversation()->createEvent($eventRequest); \ No newline at end of file diff --git a/conversation/event/delete-event.php b/conversation/event/delete-event.php new file mode 100644 index 0000000..79277f7 --- /dev/null +++ b/conversation/event/delete-event.php @@ -0,0 +1,16 @@ +conversation()->deleteEventById(EVENT_ID, CONVERSATION_ID); diff --git a/conversation/event/get-event.php b/conversation/event/get-event.php new file mode 100644 index 0000000..1dde974 --- /dev/null +++ b/conversation/event/get-event.php @@ -0,0 +1,16 @@ +conversation()->getEventById(EVENT_ID, CONVERSATION_ID); diff --git a/conversation/event/list-events.php b/conversation/event/list-events.php new file mode 100644 index 0000000..6bc5538 --- /dev/null +++ b/conversation/event/list-events.php @@ -0,0 +1,16 @@ +conversation()->delete(CONVERSATION_ID); diff --git a/conversation/member/create-member.php b/conversation/member/create-member.php new file mode 100644 index 0000000..0a62b0d --- /dev/null +++ b/conversation/member/create-member.php @@ -0,0 +1,25 @@ +conversation()->createMember($createMemberRequest, CONVERSATION_ID); diff --git a/conversation/member/delete-member.php b/conversation/member/delete-member.php new file mode 100644 index 0000000..9ebfc0f --- /dev/null +++ b/conversation/member/delete-member.php @@ -0,0 +1,16 @@ +conversation()->deleteMember(MEMBER_ID, CONVERSATION_ID); \ No newline at end of file diff --git a/conversation/member/get-member.php b/conversation/member/get-member.php new file mode 100644 index 0000000..45ba703 --- /dev/null +++ b/conversation/member/get-member.php @@ -0,0 +1,16 @@ +conversation()->getMemberByConversationId(MEMBER_ID, CONVERSATION_ID); \ No newline at end of file diff --git a/conversation/member/list-members.php b/conversation/member/list-members.php new file mode 100644 index 0000000..1118932 --- /dev/null +++ b/conversation/member/list-members.php @@ -0,0 +1,16 @@ +conversation()->listMembersByConversationId(CONVERSATION_ID); \ No newline at end of file diff --git a/conversation/member/update-member.php b/conversation/member/update-member.php new file mode 100644 index 0000000..c7bee96 --- /dev/null +++ b/conversation/member/update-member.php @@ -0,0 +1,22 @@ +conversation()->updateMember($updateMemberRequest); \ No newline at end of file diff --git a/conversation/user/create-user.php b/conversation/user/create-user.php new file mode 100644 index 0000000..5797f32 --- /dev/null +++ b/conversation/user/create-user.php @@ -0,0 +1,21 @@ + USER_NAME, + 'displayName' => USER_DISPLAY_NAME +]; + +$user = new \Vonage\Users\User(); +$user->fromArray($userData); + +$client->users()->createUser($user); \ No newline at end of file diff --git a/conversation/user/delete-user.php b/conversation/user/delete-user.php new file mode 100644 index 0000000..c35e5b4 --- /dev/null +++ b/conversation/user/delete-user.php @@ -0,0 +1,13 @@ +users()->deleteUser(USER_ID); \ No newline at end of file diff --git a/conversation/user/get-user.php b/conversation/user/get-user.php new file mode 100644 index 0000000..0cee847 --- /dev/null +++ b/conversation/user/get-user.php @@ -0,0 +1,13 @@ +users()->getUser(USER_ID); \ No newline at end of file diff --git a/conversation/user/list-user-conversations.php b/conversation/user/list-user-conversations.php new file mode 100644 index 0000000..8bd6d69 --- /dev/null +++ b/conversation/user/list-user-conversations.php @@ -0,0 +1,13 @@ +conversation()->listUserConversationsByUserId(USER_ID); \ No newline at end of file diff --git a/conversation/user/list-users.php b/conversation/user/list-users.php new file mode 100644 index 0000000..4522251 --- /dev/null +++ b/conversation/user/list-users.php @@ -0,0 +1,13 @@ +users()->listUsers(); \ No newline at end of file diff --git a/conversation/user/update-user.php b/conversation/user/update-user.php new file mode 100644 index 0000000..3d211ba --- /dev/null +++ b/conversation/user/update-user.php @@ -0,0 +1,17 @@ +users()->getUser(USER_ID); +$user->setDisplayName(USER_NEW_DISPLAY_NAME); +$user->setName(USER_NEW_NAME); + +$client->users()->updateUser($user); \ No newline at end of file diff --git a/meetings/create-instant-room.php b/meetings/create-instant-room.php new file mode 100644 index 0000000..4f33fe8 --- /dev/null +++ b/meetings/create-instant-room.php @@ -0,0 +1,12 @@ +fromArray(['display_name' => ROOM_DISPLAY_NAME]); +$meeting = $client->meetings()->createRoom($room); \ No newline at end of file diff --git a/meetings/create-long-term-room.php b/meetings/create-long-term-room.php new file mode 100644 index 0000000..15a5b97 --- /dev/null +++ b/meetings/create-long-term-room.php @@ -0,0 +1,17 @@ +fromArray([ + 'display_name' => ROOM_DISPLAY_NAME, + 'type' => 'long_term', + 'expires_at' => '2023-01-30T00:47:04+0000' +]); + +$meeting = $client->meetings()->createRoom($room); \ No newline at end of file diff --git a/messages/inbound-message.php b/messages/inbound-message.php new file mode 100644 index 0000000..f425253 --- /dev/null +++ b/messages/inbound-message.php @@ -0,0 +1,15 @@ +messages()->send($message); \ No newline at end of file diff --git a/messages/messenger/send-file.php b/messages/messenger/send-file.php index bc5cb81..b03241b 100644 --- a/messages/messenger/send-file.php +++ b/messages/messenger/send-file.php @@ -13,8 +13,10 @@ 'https://example.com/file.pdf', ); -$message = new \Vonage\Messages\MessageType\Messenger\MessengerFile( +$message = new \Vonage\Messages\Channel\Messenger\MessengerFile( TO_NUMBER, FROM_NUMBER, $fileObject ); + +$client->messages()->send($message); \ No newline at end of file diff --git a/messages/messenger/send-image.php b/messages/messenger/send-image.php index e65a9a7..83b425b 100644 --- a/messages/messenger/send-image.php +++ b/messages/messenger/send-image.php @@ -14,8 +14,10 @@ 'This is an image' ); -$message = new \Vonage\Messages\MessageType\Messenger\MessengerImage( +$message = new \Vonage\Messages\Channel\Messenger\MessengerImage( TO_NUMBER, FROM_NUMBER, $imageObject ); + +$client->messages()->send($message); \ No newline at end of file diff --git a/messages/messenger/send-text.php b/messages/messenger/send-text.php index e49eecd..cde1edf 100644 --- a/messages/messenger/send-text.php +++ b/messages/messenger/send-text.php @@ -9,8 +9,10 @@ $client = new \Vonage\Client($keypair); -$message = new \Vonage\Messages\MessageType\Messenger\MessengerText( +$message = new \Vonage\Messages\Channel\Messenger\MessengerText( TO_NUMBER, FROM_NUMBER, 'This is a text message sent using the Vonage PHP SDK' ); + +$client->messages()->send($message); \ No newline at end of file diff --git a/messages/messenger/send-video.php b/messages/messenger/send-video.php index c637796..5b1678c 100644 --- a/messages/messenger/send-video.php +++ b/messages/messenger/send-video.php @@ -14,8 +14,10 @@ 'This is an video file' ); -$message = new \Vonage\Messages\MessageType\Messenger\MessengerVideo( +$message = new \Vonage\Messages\Channel\Messenger\MessengerVideo( TO_NUMBER, FROM_NUMBER, $videoObject ); + +$client->messages()->send($message); \ No newline at end of file diff --git a/messages/mms/send-mms-audio.php b/messages/mms/send-mms-audio.php new file mode 100644 index 0000000..c9c7f88 --- /dev/null +++ b/messages/mms/send-mms-audio.php @@ -0,0 +1,22 @@ +messages()->send($mms); diff --git a/messages/mms/send-mms-content.php b/messages/mms/send-mms-content.php new file mode 100644 index 0000000..ed1512c --- /dev/null +++ b/messages/mms/send-mms-content.php @@ -0,0 +1,30 @@ +messages()->send($mms); + + diff --git a/messages/mms/send-mms-file.php b/messages/mms/send-mms-file.php new file mode 100644 index 0000000..1f1d869 --- /dev/null +++ b/messages/mms/send-mms-file.php @@ -0,0 +1,23 @@ +messages()->send($mms); + diff --git a/messages/mms/send-mms-text.php b/messages/mms/send-mms-text.php new file mode 100644 index 0000000..8f9ad37 --- /dev/null +++ b/messages/mms/send-mms-text.php @@ -0,0 +1,19 @@ +messages()->send($mms); + diff --git a/messages/mms/send-mms-vcard.php b/messages/mms/send-mms-vcard.php new file mode 100644 index 0000000..6ad133c --- /dev/null +++ b/messages/mms/send-mms-vcard.php @@ -0,0 +1,22 @@ +messages()->send($mms); diff --git a/messages/mms/send-mms-video.php b/messages/mms/send-mms-video.php new file mode 100644 index 0000000..cec011c --- /dev/null +++ b/messages/mms/send-mms-video.php @@ -0,0 +1,22 @@ +messages()->send($mms); diff --git a/messages/mms/send-mms.php b/messages/mms/send-mms.php index faef737..3b42093 100644 --- a/messages/mms/send-mms.php +++ b/messages/mms/send-mms.php @@ -10,12 +10,14 @@ $client = new \Vonage\Client($keypair); $image = new \Vonage\Messages\MessageObjects\ImageObject( - 'https://example.com/image.jpg', + MESSAGES_IMAGE_URL, 'A MMS image message, with caption, sent using the Vonage Messages API' ); -$mms = new \Vonage\Messages\MessageType\MMS\MMSImage( +$mms = new \Vonage\Messages\Channel\MMS\MMSImage( TO_NUMBER, FROM_NUMBER, $image ); + +$client->messages()->send($mms); diff --git a/messages/rcs/revoke-message.php b/messages/rcs/revoke-message.php new file mode 100644 index 0000000..af31a35 --- /dev/null +++ b/messages/rcs/revoke-message.php @@ -0,0 +1,15 @@ +messages()->updateRcsStatus($messageUuid, \Vonage\Messages\Client::RCS_STATUS_REVOKED); diff --git a/messages/rcs/send-file.php b/messages/rcs/send-file.php new file mode 100644 index 0000000..ad2088f --- /dev/null +++ b/messages/rcs/send-file.php @@ -0,0 +1,21 @@ +messages()->send($rcsFile); diff --git a/messages/rcs/send-image.php b/messages/rcs/send-image.php new file mode 100644 index 0000000..26c810a --- /dev/null +++ b/messages/rcs/send-image.php @@ -0,0 +1,21 @@ +messages()->send($rcsImage); diff --git a/messages/rcs/send-rich-card-carousel.php b/messages/rcs/send-rich-card-carousel.php new file mode 100644 index 0000000..b47a09c --- /dev/null +++ b/messages/rcs/send-rich-card-carousel.php @@ -0,0 +1,67 @@ + [ + "richCard" => [ + "carouselCard" => [ + "cardWidth" => "MEDIUM", + "cardContents" => [ + [ + "title" => "Option 1: Photo", + "description" => "Do you prefer this photo?", + "suggestions" => [ + [ + "reply" => [ + "text" => "Option 1", + "postbackData" => "card_1" + ] + ] + ], + "media" => [ + "height" => "MEDIUM", + "contentInfo" => [ + "fileUrl" => "'\$IMAGE_URL'", + "forceRefresh" => "false" + ] + ] + ], + [ + "title" => "Option 2: Video", + "description" => "Or this video?", + "suggestions" => [ + [ + "reply" => [ + "text" => "Option 2", + "postbackData" => "card_2" + ] + ] + ], + "media" => [ + "height" => "MEDIUM", + "contentInfo" => [ + "fileUrl" => "'\$VIDEO_URL'", + "forceRefresh" => "false" + ] + ] + ] + ] + ] + ] + ] + ] +); + +$client->messages()->send($rcsCard); diff --git a/messages/rcs/send-rich-card-standalone.php b/messages/rcs/send-rich-card-standalone.php new file mode 100644 index 0000000..7140297 --- /dev/null +++ b/messages/rcs/send-rich-card-standalone.php @@ -0,0 +1,53 @@ + [ + "richCard" => [ + "standaloneCard" => [ + "thumbnailImageAlignment" => "RIGHT", + "cardOrientation" => "VERTICAL", + "cardContent" => [ + "title" => "Quick question", + "description" => "Do you like this picture?", + "media" => [ + "height" => "TALL", + "contentInfo" => [ + "fileUrl" => "'\$IMAGE_URL'", + "forceRefresh" => "false" + ] + ], + "suggestions" => [ + [ + "reply" => [ + "text" => "Yes", + "postbackData" => "suggestion_1" + ] + ], + [ + "reply" => [ + "text" => "I love it!", + "postbackData" => "suggestion_2" + ] + ] + ] + ] + ] + ] + ] + ] +); + +$client->messages()->send($rcsCard); diff --git a/messages/rcs/send-suggested-action-create-calendar-event.php b/messages/rcs/send-suggested-action-create-calendar-event.php new file mode 100644 index 0000000..ca307cc --- /dev/null +++ b/messages/rcs/send-suggested-action-create-calendar-event.php @@ -0,0 +1,39 @@ + [ + "text" => "Product Launch: Save the date!", + "suggestions" => [ + [ + "action" => [ + "text" => "Save to calendar", + "postbackData" => "postback_data_1234", + "fallbackUrl" => "https://www.google.com/calendar", + "createCalendarEventAction" => [ + "startTime" => "2024-06-28T19:00:00Z", + "endTime" => "2024-06-28T20:00:00Z", + "title" => "Vonage API Product Launch", + "description" => + "Event to demo Vonage\'s new and exciting API product", + ], + ], + ], + ], + ], + ] +); + +$client->messages()->send($rcsCard); diff --git a/messages/rcs/send-suggested-action-dial.php b/messages/rcs/send-suggested-action-dial.php new file mode 100644 index 0000000..6aaae6d --- /dev/null +++ b/messages/rcs/send-suggested-action-dial.php @@ -0,0 +1,33 @@ + [ + "text" => "Call us to claim your free gift!", + "suggestions" => [ + [ + "action" => [ + "text" => "Call now!", + "postbackData" => "postback_data_1234", + "fallbackUrl" => "https://www.example.com/contact/", + "dialAction" => ["phoneNumber" => "+447900000000"], + ], + ], + ], + ], + ] +); + +$client->messages()->send($rcsCard); diff --git a/messages/rcs/send-suggested-action-multiple.php b/messages/rcs/send-suggested-action-multiple.php new file mode 100644 index 0000000..d4ccff4 --- /dev/null +++ b/messages/rcs/send-suggested-action-multiple.php @@ -0,0 +1,41 @@ + [ + "text" => + "Need some help? Call us now or visit our website for more information.", + "suggestions" => [ + [ + "action" => [ + "text" => "Call us", + "postbackData" => "postback_data_1234", + "fallbackUrl" => "https://www.example.com/contact/", + "dialAction" => ["phoneNumber" => "+447900000000"], + ], + ], + [ + "action" => [ + "text" => "Visit site", + "postbackData" => "postback_data_1234", + "openUrlAction" => ["url" => "http://example.com/"], + ], + ], + ], + ], + ] +); + +$client->messages()->send($rcsCard); diff --git a/messages/rcs/send-suggested-action-open-url.php b/messages/rcs/send-suggested-action-open-url.php new file mode 100644 index 0000000..1d05abf --- /dev/null +++ b/messages/rcs/send-suggested-action-open-url.php @@ -0,0 +1,32 @@ + [ + "text" => "Check out our latest offers!", + "suggestions" => [ + [ + "action" => [ + "text" => "Open product page", + "postbackData" => "postback_data_1234", + "openUrlAction" => ["url" => "http://example.com/"], + ], + ], + ], + ], + ] +); + +$client->messages()->send($rcsCard); diff --git a/messages/rcs/send-suggested-action-share-location.php b/messages/rcs/send-suggested-action-share-location.php new file mode 100644 index 0000000..6e074c9 --- /dev/null +++ b/messages/rcs/send-suggested-action-share-location.php @@ -0,0 +1,33 @@ + [ + "text" => + "Your driver will come and meet you at your specified location.", + "suggestions" => [ + [ + "action" => [ + "text" => "Share a location", + "postbackData" => "postback_data_1234", + "shareLocationAction" => [], + ], + ], + ], + ], + ] +); + +$client->messages()->send($rcsCard); diff --git a/messages/rcs/send-suggested-action-view-location.php b/messages/rcs/send-suggested-action-view-location.php new file mode 100644 index 0000000..dc28708 --- /dev/null +++ b/messages/rcs/send-suggested-action-view-location.php @@ -0,0 +1,40 @@ + [ + "text" => "Drop by our office!", + "suggestions" => [ + [ + "action" => [ + "text" => "View map", + "postbackData" => "postback_data_1234", + "fallbackUrl" => + "https://www.google.com/maps/place/Vonage/@51.5230371,-0.0852492,15z", + "viewLocationAction" => [ + "latLong" => [ + "latitude" => "51.5230371", + "longitude" => "-0.0852492", + ], + "label" => "Vonage London Office", + ], + ], + ], + ], + ], + ] +); + +$client->messages()->send($rcsCard); diff --git a/messages/rcs/send-suggested-reply.php b/messages/rcs/send-suggested-reply.php new file mode 100644 index 0000000..ad03061 --- /dev/null +++ b/messages/rcs/send-suggested-reply.php @@ -0,0 +1,37 @@ + [ + "text" => "What do you think of Vonage APIs?", + "suggestions" => [ + [ + "reply" => [ + "text" => "They\'re great!", + "postbackData" => "suggestion_1", + ], + ], + [ + "reply" => [ + "text" => "They\'re awesome!", + "postbackData" => "suggestion_2", + ], + ], + ], + ], + ] +); + +$client->messages()->send($rcsCard); diff --git a/messages/rcs/send-text.php b/messages/rcs/send-text.php new file mode 100644 index 0000000..61b1de0 --- /dev/null +++ b/messages/rcs/send-text.php @@ -0,0 +1,19 @@ +messages()->send($rcsText); diff --git a/messages/rcs/send-video.php b/messages/rcs/send-video.php new file mode 100644 index 0000000..f19acf5 --- /dev/null +++ b/messages/rcs/send-video.php @@ -0,0 +1,21 @@ +messages()->send($rcsImage); diff --git a/messages/sandbox/messenger/send-text.php b/messages/sandbox/messenger/send-text.php new file mode 100644 index 0000000..77461dd --- /dev/null +++ b/messages/sandbox/messenger/send-text.php @@ -0,0 +1,23 @@ + MESSAGES_SANDBOX_URL + ] +); + +$message = new \Vonage\Messages\MessageType\Messenger\MessengerText( + MESSAGES_SANDBOX_ALLOW_LISTED_FB_RECIPIENT_ID, + MESSAGES_SANDBOX_FB_ID, + 'This is a Messenger text message sent using the Vonage PHP SDK via the Messages Sandbox' +); + +$response = $client->messages()->send($message); diff --git a/messages/sandbox/viber/send-text.php b/messages/sandbox/viber/send-text.php new file mode 100644 index 0000000..4a1f8ab --- /dev/null +++ b/messages/sandbox/viber/send-text.php @@ -0,0 +1,23 @@ + MESSAGES_SANDBOX_URL + ] +); + +$viber = new \Vonage\Messages\MessageType\Viber\ViberText( + MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER, + MESSAGES_SANDBOX_VIBER_SERVICE_ID, + 'This is a Viber text message sent using the Vonage PHP SDK via the Messages Sandbox' +); + +$response = $client->messages()->send($message); diff --git a/messages/sandbox/whatsapp/send-text.php b/messages/sandbox/whatsapp/send-text.php new file mode 100644 index 0000000..cb788e3 --- /dev/null +++ b/messages/sandbox/whatsapp/send-text.php @@ -0,0 +1,23 @@ + MESSAGES_SANDBOX_URL + ] +); + +$whatsApp = new \Vonage\Messages\MessageType\WhatsApp\WhatsAppText( + MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER, + MESSAGES_SANDBOX_WHATSAPP_NUMBER, + 'This is a WhatsApp text message sent using the Vonage PHP SDK via the Messages Sandbox via the Messages Sandbox' +); + +$response = $client->messages()->send($message); diff --git a/messages/signed-webhooks/verify-webhook.php b/messages/signed-webhooks/verify-webhook.php index ccd7fd0..f57a71c 100644 --- a/messages/signed-webhooks/verify-webhook.php +++ b/messages/signed-webhooks/verify-webhook.php @@ -14,5 +14,5 @@ $client->sms()->send($message); // Incoming Request -$signature = new Vonage\Client\Signature(VONAGE_API_KEY, VONAGE_SIGNATURE_SECRET, 'sha256'); -$isValid = $signature->check($_GET['sig']); \ No newline at end of file +$signature = new Vonage\Client\Signature($_GET, VONAGE_SIGNATURE_SECRET, 'sha256'); +$isValid = $signature->check($_GET['sig']); diff --git a/messages/sms/send-sms.php b/messages/sms/send-sms.php index 958aabd..50983b1 100644 --- a/messages/sms/send-sms.php +++ b/messages/sms/send-sms.php @@ -9,7 +9,7 @@ $client = new \Vonage\Client($keypair); -$sms = new \Vonage\Messages\MessageType\SMS\SMSText( +$sms = new \Vonage\Messages\Channel\SMS\SMSText( TO_NUMBER, FROM_NUMBER, 'This is an SMS sent using the Vonage PHP SDK' diff --git a/messages/viber/send-file.php b/messages/viber/send-file.php new file mode 100644 index 0000000..1a45f9d --- /dev/null +++ b/messages/viber/send-file.php @@ -0,0 +1,18 @@ +messages()->send($viber); \ No newline at end of file diff --git a/messages/viber/send-image.php b/messages/viber/send-image.php index 47bffdb..2920259 100644 --- a/messages/viber/send-image.php +++ b/messages/viber/send-image.php @@ -14,8 +14,10 @@ 'This is an image' ); -$viber = new \Vonage\Messages\MessageType\Viber\ViberImage( +$viber = new \Vonage\Messages\Channel\Viber\ViberImage( TO_NUMBER, FROM_NUMBER, $imageObject ); + +$client->messages()->send($viber); \ No newline at end of file diff --git a/messages/viber/send-text.php b/messages/viber/send-text.php index 411f499..d09f864 100644 --- a/messages/viber/send-text.php +++ b/messages/viber/send-text.php @@ -9,8 +9,10 @@ $client = new \Vonage\Client($keypair); -$viber = new \Vonage\Messages\MessageType\Viber\ViberText( +$viber = new \Vonage\Messages\Channel\Viber\ViberText( TO_NUMBER, FROM_NUMBER, 'This is a text message sent using the Vonage PHP SDK' ); + +$client->messages()->send($viber); \ No newline at end of file diff --git a/messages/viber/send-video.php b/messages/viber/send-video.php new file mode 100644 index 0000000..62bf20f --- /dev/null +++ b/messages/viber/send-video.php @@ -0,0 +1,18 @@ +messages()->send($viber); \ No newline at end of file diff --git a/messages/whatsapp/mark-as-read.php b/messages/whatsapp/mark-as-read.php new file mode 100644 index 0000000..c55e77a --- /dev/null +++ b/messages/whatsapp/mark-as-read.php @@ -0,0 +1,13 @@ +messages()->getAPIResource()->setBaseUrl('https://api-eu.nexmo.com/v1'); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-audio.php b/messages/whatsapp/send-audio.php index 267b333..3143b2a 100644 --- a/messages/whatsapp/send-audio.php +++ b/messages/whatsapp/send-audio.php @@ -14,8 +14,10 @@ 'This is an audio file' ); -$whatsApp = new \Vonage\Messages\MessageType\WhatsApp\WhatsAppAudio( +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppAudio( TO_NUMBER, FROM_NUMBER, $audioObject ); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-authentication-template.php b/messages/whatsapp/send-authentication-template.php new file mode 100644 index 0000000..beac0a5 --- /dev/null +++ b/messages/whatsapp/send-authentication-template.php @@ -0,0 +1,58 @@ + TO_NUMBER, + "from" => WHATSAPP_NUMBER, + "channel" => "whatsapp", + "message_type" => "custom", + "custom" => [ + "type" => "template", + "template" => [ + "name" => WHATSAPP_AUTH_TEMPLATE_NAME, + "language" => [ + "policy" => "deterministic", + "code" => "en" + ], + "components" => [ + [ + "type" => "body", + "parameters" => [ + [ + "type" => "text", + "text" => '$OTP' + ] + ] + ], + [ + "type" => "button", + "sub_type" => "url", + "index" => "0", + "parameters" => [ + [ + "type" => "text", + "text" => '$OTP' + ] + ] + ] + ] + ] + ] +]; + + +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( + TO_NUMBER, + FROM_NUMBER, + $custom +); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-button-link.php b/messages/whatsapp/send-button-link.php index c7cb81b..59402ad 100644 --- a/messages/whatsapp/send-button-link.php +++ b/messages/whatsapp/send-button-link.php @@ -46,8 +46,10 @@ ], ]; -$whatsApp = new \Vonage\Messages\MessageType\WhatsApp\WhatsAppCustom( +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( TO_NUMBER, FROM_NUMBER, $custom ); + +$client->messages()->send($whatsApp); diff --git a/messages/whatsapp/send-button-quick-reply.php b/messages/whatsapp/send-button-quick-reply.php index c82b9c5..440bc9c 100644 --- a/messages/whatsapp/send-button-quick-reply.php +++ b/messages/whatsapp/send-button-quick-reply.php @@ -51,8 +51,10 @@ ], ]; -$whatsApp = new \Vonage\Messages\MessageType\WhatsApp\WhatsAppCustom( +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( TO_NUMBER, FROM_NUMBER, $custom ); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-contact.php b/messages/whatsapp/send-contact.php index c6de6af..ae3be75 100644 --- a/messages/whatsapp/send-contact.php +++ b/messages/whatsapp/send-contact.php @@ -61,8 +61,10 @@ ], ]; -$whatsApp = new \Vonage\Messages\MessageType\WhatsApp\WhatsAppCustom( +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( TO_NUMBER, FROM_NUMBER, $custom ); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-file.php b/messages/whatsapp/send-file.php index e4f1490..3f5cdd1 100644 --- a/messages/whatsapp/send-file.php +++ b/messages/whatsapp/send-file.php @@ -14,8 +14,10 @@ 'This is a whatsapp file' ); -$whatsApp = new \Vonage\Messages\MessageType\WhatsApp\WhatsAppFile( +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppFile( TO_NUMBER, FROM_NUMBER, $fileObject ); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-image.php b/messages/whatsapp/send-image.php index f18c7ad..343beb3 100644 --- a/messages/whatsapp/send-image.php +++ b/messages/whatsapp/send-image.php @@ -14,8 +14,10 @@ 'This is a whatsapp image' ); -$whatsApp = new \Vonage\Messages\MessageType\Messenger\MessengerImage( +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppImage( TO_NUMBER, FROM_NUMBER, $imageObject ); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-location.php b/messages/whatsapp/send-location.php index 5a8c45a..d456c36 100644 --- a/messages/whatsapp/send-location.php +++ b/messages/whatsapp/send-location.php @@ -19,8 +19,10 @@ ], ]; -$whatsApp = new \Vonage\Messages\MessageType\WhatsApp\WhatsAppCustom( +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( TO_NUMBER, FROM_NUMBER, $custom ); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-media-mtm.php b/messages/whatsapp/send-media-mtm.php index aca1823..6c8817d 100644 --- a/messages/whatsapp/send-media-mtm.php +++ b/messages/whatsapp/send-media-mtm.php @@ -12,7 +12,6 @@ $custom = [ "type" => "template", "template" => [ - "namespace" => WHATSAPP_TEMPLATE_NAMESPACE, "name" => WHATSAPP_TEMPLATE_NAME, "language" => ["policy" => "deterministic", "code" => "en"], "components" => [ @@ -20,12 +19,9 @@ "type" => "header", "parameters" => [ [ - "type" => "location", - "location" => [ - "longitude" => -122.425332, - "latitude" => 37.758056, - "name" => "Facebook HQ", - "address" => "1 Hacker Way, Menlo Park, CA 94025", + "type" => "image", + "image" => [ + "link" => IMAGE_URL, ], ], ], @@ -33,17 +29,18 @@ [ "type" => "body", "parameters" => [ - ["type" => "text", "text" => "Value 1"], - ["type" => "text", "text" => "Value 2"], - ["type" => "text", "text" => "Value 3"], + "type" => "text", + "text" => WHATSAPP_TEMPLATE_REPLACEMENT_TEXT, ], ], ], ], ]; -$whatsApp = new \Vonage\Messages\MessageType\WhatsApp\WhatsAppCustom( +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( TO_NUMBER, FROM_NUMBER, $custom ); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-mtm.php b/messages/whatsapp/send-mtm.php index 5c32319..e922791 100644 --- a/messages/whatsapp/send-mtm.php +++ b/messages/whatsapp/send-mtm.php @@ -12,14 +12,16 @@ $custom = [ "name" => WHATSAPP_TEMPLATE_NAMESPACE . ":" . WHATSAPP_TEMPLATE_NAME, "parameters" => [ - ["default" => "Vonage Verification"], - ["default" => "64873"], - ["default" => "10"], + "Vonage Verification", + "64873", + "10", ], ]; -$whatsApp = new \Vonage\Messages\MessageType\WhatsApp\WhatsAppCustom( +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( TO_NUMBER, FROM_NUMBER, $custom ); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-multi-product.php b/messages/whatsapp/send-multi-product.php new file mode 100644 index 0000000..beae509 --- /dev/null +++ b/messages/whatsapp/send-multi-product.php @@ -0,0 +1,53 @@ + "interactive", + "interactive" => [ + "type" => "product_list", + "header" => [ + "type" => "text", + "text" => "Our top products" + ], + "body" => [ + "text" => "Check out these great products" + ], + "footer" => [ + "text" => "Sale now on!" + ], + "action" => [ + "catalog_id" => CATALOG_ID, + "sections" => [ + [ + "title" => "Cool products", + "product_items" => [ + ["product_retailer_id" => PRODUCT_ID], + ["product_retailer_id" => PRODUCT_ID] + ] + ], + [ + "title" => "Awesome products", + "product_items" => [ + ["product_retailer_id" => PRODUCT_ID] + ] + ] + ] + ] + ] +]; + +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( + TO_NUMBER, + FROM_NUMBER, + $custom +); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-reaction.php b/messages/whatsapp/send-reaction.php new file mode 100644 index 0000000..1ac5f4b --- /dev/null +++ b/messages/whatsapp/send-reaction.php @@ -0,0 +1,32 @@ + "reaction", + "reaction" => [ + "action" => "react", + "emoji" => EMOJI + ], + "context" => [ + "message_uuid" => MESSAGE_UUID + ], + "to" => TO_NUMBER, + "from" => WHATSAPP_NUMBER, + "channel" => "whatsapp" +]; + +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( + TO_NUMBER, + FROM_NUMBER, + $custom +); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-single-product.php b/messages/whatsapp/send-single-product.php new file mode 100644 index 0000000..42d666a --- /dev/null +++ b/messages/whatsapp/send-single-product.php @@ -0,0 +1,41 @@ + TO_NUMBER, + "from" => WHATSAPP_NUMBER, + "channel" => "whatsapp", + "message_type" => "custom", + "custom" => [ + "type" => "interactive", + "interactive" => [ + "type" => "product", + "body" => [ + "text" => "Check out this cool product" + ], + "footer" => [ + "text" => "Sale now on!" + ], + "action" => [ + "catalog_id" => CATALOG_ID, + "product_retailer_id" => PRODUCT_ID + ] + ] + ] +]; + +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( + TO_NUMBER, + FROM_NUMBER, + $custom +); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-sticker-id.php b/messages/whatsapp/send-sticker-id.php new file mode 100644 index 0000000..af91e2a --- /dev/null +++ b/messages/whatsapp/send-sticker-id.php @@ -0,0 +1,29 @@ + "sticker", + "sticker" => [ + "id" => STICKER_ID + ], + "to" => TO_NUMBER, + "from" => WHATSAPP_NUMBER, + "channel" => "whatsapp" +]; + + +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( + TO_NUMBER, + FROM_NUMBER, + $custom +); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-sticker-url.php b/messages/whatsapp/send-sticker-url.php new file mode 100644 index 0000000..b99fe5b --- /dev/null +++ b/messages/whatsapp/send-sticker-url.php @@ -0,0 +1,29 @@ + "sticker", + "sticker" => [ + "url" => STICKER_URL + ], + "to" => TO_NUMBER, + "from" => WHATSAPP_NUMBER, + "channel" => "whatsapp" +]; + + +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( + TO_NUMBER, + FROM_NUMBER, + $custom +); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-text.php b/messages/whatsapp/send-text.php index 8861a77..3d536ea 100644 --- a/messages/whatsapp/send-text.php +++ b/messages/whatsapp/send-text.php @@ -9,8 +9,10 @@ $client = new \Vonage\Client($keypair); -$whatsApp = new \Vonage\Messages\MessageType\WhatsApp\WhatsAppText( +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppText( TO_NUMBER, FROM_NUMBER, 'This is a text message sent using the Vonage PHP SDK' ); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-unreaction.php b/messages/whatsapp/send-unreaction.php new file mode 100644 index 0000000..b145b13 --- /dev/null +++ b/messages/whatsapp/send-unreaction.php @@ -0,0 +1,31 @@ + "reaction", + "reaction" => [ + "action" => "unreact" + ], + "context" => [ + "message_uuid" => MESSAGE_UUID + ], + "to" => TO_NUMBER, + "from" => WHATSAPP_NUMBER, + "channel" => "whatsapp" +]; + +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( + TO_NUMBER, + FROM_NUMBER, + $custom +); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/messages/whatsapp/send-video.php b/messages/whatsapp/send-video.php index 039d80c..5dc5c4c 100644 --- a/messages/whatsapp/send-video.php +++ b/messages/whatsapp/send-video.php @@ -14,8 +14,10 @@ 'This is an video file' ); -$whatsApp = new \Vonage\Messages\MessageType\WhatsApp\WhatsAppVideo( +$whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppVideo( TO_NUMBER, FROM_NUMBER, $videoObject ); + +$client->messages()->send($whatsApp); \ No newline at end of file diff --git a/network-apis/number-verification/verify-phone-number.php b/network-apis/number-verification/verify-phone-number.php new file mode 100644 index 0000000..c6bebeb --- /dev/null +++ b/network-apis/number-verification/verify-phone-number.php @@ -0,0 +1,14 @@ +numberVerification()->verifyNumber(PHONE_NUMBER); \ No newline at end of file diff --git a/network-apis/sim-swap/check-sim-swap-date.php b/network-apis/sim-swap/check-sim-swap-date.php new file mode 100644 index 0000000..e82a991 --- /dev/null +++ b/network-apis/sim-swap/check-sim-swap-date.php @@ -0,0 +1,14 @@ +simswap()->checkSimSwapDate(PHONE_NUMBER); \ No newline at end of file diff --git a/network-apis/sim-swap/check-sim-swap.php b/network-apis/sim-swap/check-sim-swap.php new file mode 100644 index 0000000..a6b2777 --- /dev/null +++ b/network-apis/sim-swap/check-sim-swap.php @@ -0,0 +1,14 @@ +simswap()->checkSimSwap(PHONE_NUMBER); \ No newline at end of file diff --git a/sms/send-signed-sms.php b/sms/send-signed-sms.php index 2a2b83f..99e5270 100644 --- a/sms/send-signed-sms.php +++ b/sms/send-signed-sms.php @@ -3,7 +3,7 @@ require_once __DIR__ . '/../config.php'; require_once __DIR__ . '/../vendor/autoload.php'; -$signed = new Nexmo\Client\Credentials\SignatureSecret( +$signed = new \Vonage\Client\Credentials\SignatureSecret( VONAGE_API_KEY, VONAGE_API_SIGNATURE_SECRET, 'md5hash' diff --git a/sms/send-sms-basic.php b/sms/send-sms-basic.php new file mode 100644 index 0000000..af77d53 --- /dev/null +++ b/sms/send-sms-basic.php @@ -0,0 +1,19 @@ +sms()->send( + new \Vonage\SMS\Message\SMS(TO_NUMBER, BRAND_NAME, 'A text message sent using the Vonage SMS API') +); + +$message = $response->current(); + +if ($message->getStatus() == 0) { + echo "The message was sent successfully\n"; +} else { + echo "The message failed with status: " . $message->getStatus() . "\n"; +} diff --git a/sms/send-sms.php b/sms/send-sms.php index 3420976..14733fb 100644 --- a/sms/send-sms.php +++ b/sms/send-sms.php @@ -3,11 +3,11 @@ require_once __DIR__ . '/../config.php'; require_once __DIR__ . '/../vendor/autoload.php'; -$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET); -$client = new \Vonage\Client($basic); +$keypair = new \Vonage\Client\Credentials\Keypair(VONAGE_PRIVATE_KEY, VONAGE_APPLICATION_ID); +$client = new \Vonage\Client($keypair); $response = $client->sms()->send( - new \Vonage\SMS\Message\SMS(TO_NUMBER, BRAND_NAME, 'A text message sent using the Nexmo SMS API') + new \Vonage\SMS\Message\SMS(TO_NUMBER, BRAND_NAME, 'A text message sent using the Vonage SMS API') ); $message = $response->current(); diff --git a/subaccounts/create-subaccount.php b/subaccounts/create-subaccount.php new file mode 100644 index 0000000..0b9a989 --- /dev/null +++ b/subaccounts/create-subaccount.php @@ -0,0 +1,13 @@ +setName(NEW_SUBACCOUNT_NAME); +$account->setSecret(NEW_SUBACCOUNT_SECRET); + +$client->subaccount()->createSubaccount(VONAGE_API_KEY, $account); \ No newline at end of file diff --git a/subaccounts/get-balance-transfers.php b/subaccounts/get-balance-transfers.php new file mode 100644 index 0000000..3eb27af --- /dev/null +++ b/subaccounts/get-balance-transfers.php @@ -0,0 +1,12 @@ + START_DATE +]); + +$balanceTransfers = $client->subaccount()->getBalanceTransfers(VONAGE_API_KEY, $startDateFilter); \ No newline at end of file diff --git a/subaccounts/get-credit-transfers.php b/subaccounts/get-credit-transfers.php new file mode 100644 index 0000000..b183852 --- /dev/null +++ b/subaccounts/get-credit-transfers.php @@ -0,0 +1,12 @@ + START_DATE +]); + +$creditTransfers = $client->subaccount()->getCreditTransfers(VONAGE_API_KEY, $startDateFilter); \ No newline at end of file diff --git a/subaccounts/get-subaccount.php b/subaccounts/get-subaccount.php new file mode 100644 index 0000000..bd758bd --- /dev/null +++ b/subaccounts/get-subaccount.php @@ -0,0 +1,9 @@ +subaccount()->getSubaccount(VONAGE_API_KEY, SUBACCOUNT_KEY); \ No newline at end of file diff --git a/subaccounts/get-subaccounts.php b/subaccounts/get-subaccounts.php new file mode 100644 index 0000000..3ef744c --- /dev/null +++ b/subaccounts/get-subaccounts.php @@ -0,0 +1,9 @@ +subaccount()->getSubaccounts(VONAGE_API_KEY); \ No newline at end of file diff --git a/subaccounts/reactivate-subaccount.php b/subaccounts/reactivate-subaccount.php new file mode 100644 index 0000000..990d6c6 --- /dev/null +++ b/subaccounts/reactivate-subaccount.php @@ -0,0 +1,13 @@ + +setSuspended(false); + +$subaccount = $client->subaccount()->updateSubaccount(VONAGE_API_KEY, SUBACCOUNT_KEY, $account); \ No newline at end of file diff --git a/subaccounts/suspend-subaccount.php b/subaccounts/suspend-subaccount.php new file mode 100644 index 0000000..a16ad78 --- /dev/null +++ b/subaccounts/suspend-subaccount.php @@ -0,0 +1,13 @@ + +setSuspended(true); + +$subaccount = $client->subaccount()->updateSubaccount(VONAGE_API_KEY, SUBACCOUNT_KEY, $account); \ No newline at end of file diff --git a/subaccounts/transfer-balance.php b/subaccounts/transfer-balance.php new file mode 100644 index 0000000..ef49cde --- /dev/null +++ b/subaccounts/transfer-balance.php @@ -0,0 +1,16 @@ + +setFrom(VONAGE_API_KEY) + ->setTo(SUBACCOUNT_KEY) + ->setAmount(250); + +$subaccount = $client->subaccount()->makeBalanceTransfer($transferRequest); \ No newline at end of file diff --git a/subaccounts/transfer-credit.php b/subaccounts/transfer-credit.php new file mode 100644 index 0000000..ffa7507 --- /dev/null +++ b/subaccounts/transfer-credit.php @@ -0,0 +1,15 @@ +setFrom(VONAGE_API_KEY) + ->setTo(SUBACCOUNT_KEY) + ->setAmount(250); + +$subaccount = $client->subaccount()->makeBalanceTransfer($transferRequest); \ No newline at end of file diff --git a/verify/request_with_workflow.php b/verify/request_with_workflow.php index eba2032..b117de1 100644 --- a/verify/request_with_workflow.php +++ b/verify/request_with_workflow.php @@ -1,4 +1,4 @@ -verify2()->cancelRequest(REQUEST_ID); diff --git a/verify2/check-verification-code.php b/verify2/check-verification-code.php new file mode 100644 index 0000000..308c3ae --- /dev/null +++ b/verify2/check-verification-code.php @@ -0,0 +1,14 @@ +verify2()->check(REQUEST_ID, CODE); +} catch (\Exception $e) { + var_dump($e->getMessage()); +} diff --git a/verify2/create-template-fragment.php b/verify2/create-template-fragment.php new file mode 100644 index 0000000..4c40f6c --- /dev/null +++ b/verify2/create-template-fragment.php @@ -0,0 +1,16 @@ +verify2()->createCustomTemplateFragment(TEMPLATE_ID, $createFragmentRequest); diff --git a/verify2/create-template.php b/verify2/create-template.php new file mode 100644 index 0000000..ecb1f6b --- /dev/null +++ b/verify2/create-template.php @@ -0,0 +1,10 @@ +verify2()->createCustomTemplate('my-custom-template'); \ No newline at end of file diff --git a/verify2/delete-fragment.php b/verify2/delete-fragment.php new file mode 100644 index 0000000..ed8bcce --- /dev/null +++ b/verify2/delete-fragment.php @@ -0,0 +1,10 @@ +verify2()->deleteCustomTemplateFragment(TEMPLATE_ID, TEMPLATE_FRAGMENT_ID); diff --git a/verify2/delete-template.php b/verify2/delete-template.php new file mode 100644 index 0000000..a610384 --- /dev/null +++ b/verify2/delete-template.php @@ -0,0 +1,10 @@ +verify2()->deleteCustomTemplate(TEMPLATE_ID); diff --git a/verify2/get-fragment.php b/verify2/get-fragment.php new file mode 100644 index 0000000..0ce4c52 --- /dev/null +++ b/verify2/get-fragment.php @@ -0,0 +1,10 @@ +verify2()->getCustomTemplateFragment(TEMPLATE_ID, TEMPLATE_FRAGMENT_ID); diff --git a/verify2/get-template.php b/verify2/get-template.php new file mode 100644 index 0000000..ffef848 --- /dev/null +++ b/verify2/get-template.php @@ -0,0 +1,10 @@ +verify2()->getCustomTemplate(TEMPLATE_ID); diff --git a/verify2/list-fragments.php b/verify2/list-fragments.php new file mode 100644 index 0000000..c71c539 --- /dev/null +++ b/verify2/list-fragments.php @@ -0,0 +1,10 @@ +verify2()->listTemplateFragments(TEMPLATE_ID); diff --git a/verify2/list-templates.php b/verify2/list-templates.php new file mode 100644 index 0000000..bb0d3ef --- /dev/null +++ b/verify2/list-templates.php @@ -0,0 +1,10 @@ +verify2()->listCustomTemplates(TEMPLATE_ID); diff --git a/verify2/send-request-email.php b/verify2/send-request-email.php new file mode 100644 index 0000000..7c76186 --- /dev/null +++ b/verify2/send-request-email.php @@ -0,0 +1,11 @@ +verify2()->startVerification($newRequest); diff --git a/verify2/send-request-silent-auth.php b/verify2/send-request-silent-auth.php new file mode 100644 index 0000000..408e1ff --- /dev/null +++ b/verify2/send-request-silent-auth.php @@ -0,0 +1,11 @@ +verify2()->startVerification($newRequest); diff --git a/verify2/send-request-sms.php b/verify2/send-request-sms.php new file mode 100644 index 0000000..634418b --- /dev/null +++ b/verify2/send-request-sms.php @@ -0,0 +1,11 @@ +verify2()->startVerification($newRequest); diff --git a/verify2/send-request-voice.php b/verify2/send-request-voice.php new file mode 100644 index 0000000..4e6201b --- /dev/null +++ b/verify2/send-request-voice.php @@ -0,0 +1,11 @@ +verify2()->startVerification($newRequest); diff --git a/verify2/send-request-whatsapp-interactive.php b/verify2/send-request-whatsapp-interactive.php new file mode 100644 index 0000000..e62823e --- /dev/null +++ b/verify2/send-request-whatsapp-interactive.php @@ -0,0 +1,11 @@ +verify2()->startVerification($newRequest); diff --git a/verify2/send-request-whatsapp.php b/verify2/send-request-whatsapp.php new file mode 100644 index 0000000..8d82c9d --- /dev/null +++ b/verify2/send-request-whatsapp.php @@ -0,0 +1,11 @@ +verify2()->startVerification($newRequest); diff --git a/verify2/send-request-with-fallback.php b/verify2/send-request-with-fallback.php new file mode 100644 index 0000000..f2878df --- /dev/null +++ b/verify2/send-request-with-fallback.php @@ -0,0 +1,13 @@ +addWorkflow($emailWorkflow); +$client->verify2()->startVerification($newRequest); diff --git a/verify2/update-template-fragment.php b/verify2/update-template-fragment.php new file mode 100644 index 0000000..8bfd297 --- /dev/null +++ b/verify2/update-template-fragment.php @@ -0,0 +1,14 @@ +verify2()->updateCustomTemplateFragment( + TEMPLATE_ID, + TEMPLATE_FRAGMENT_ID, + 'The authentication code for your ${brand} is: ${code}' +); diff --git a/verify2/update-template.php b/verify2/update-template.php new file mode 100644 index 0000000..ceec4e7 --- /dev/null +++ b/verify2/update-template.php @@ -0,0 +1,12 @@ +verify2()->updateCustomTemplate(TEMPLATE_ID, $updateRequest); diff --git a/voice/connect-call-slim/index.php b/voice/connect-call-slim/index.php index 2fabb05..5e9b318 100644 --- a/voice/connect-call-slim/index.php +++ b/voice/connect-call-slim/index.php @@ -10,16 +10,16 @@ $dotenv = Dotenv::createImmutable(__DIR__); $dotenv->load(); -define('YOUR_SECOND_NUMBER', getenv('YOUR_SECOND_NUMBER')); -define('VONAGE_NUMBER', getenv('VONAGE_NUMBER')); +define('VOICE_TO_NUMBER', getenv('VOICE_TO_NUMBER')); +define('VONAGE_VIRTUAL_NUMBER', getenv('VONAGE_VIRTUAL_NUMBER')); $app = new \Slim\App(); $app->get('/webhooks/answer', function (Request $request, Response $response) { - $numberToConnect = new \Vonage\Voice\Endpoint\Phone(YOUR_SECOND_NUMBER); + $numberToConnect = new \Vonage\Voice\Endpoint\Phone(VOICE_TO_NUMBER); $action = new \Vonage\Voice\NCCO\Action\Connect($numberToConnect); - $action->setFrom(VONAGE_NUMBER); + $action->setFrom(VONAGE_VIRTUAL_NUMBER); $ncco = new \Vonage\Voice\NCCO\NCCO(); $ncco->addAction($action); diff --git a/voice/download-a-recording/index.php b/voice/download-a-recording/index.php index 116acc4..b04d487 100644 --- a/voice/download-a-recording/index.php +++ b/voice/download-a-recording/index.php @@ -6,5 +6,5 @@ $client = new \Vonage\Client($keypair); $recordingUrl = 'https://api.nexmo.com/v1/files/'.VONAGE_RECORDING_ID; -$data = $client->get($recordingUrl); -file_put_contents($recordingId.'.mp3', $data->getBody()); +$data = $client->voice()->getRecording($recordingUrl); +file_put_contents(VONAGE_RECORDING_ID .'.mp3', $data->getContents()); diff --git a/voice/play-tts-in-to-call/index.php b/voice/play-tts-in-to-call/index.php index 248ac38..421e91e 100644 --- a/voice/play-tts-in-to-call/index.php +++ b/voice/play-tts-in-to-call/index.php @@ -4,8 +4,10 @@ $keypair = new \Vonage\Client\Credentials\Keypair(file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH), VONAGE_APPLICATION_ID); $client = new \Vonage\Client($keypair); +$action = new \Vonage\Voice\NCCO\Action\Talk(TEXT); +$action->setLanguage('en-US'); $client->voice()->playTTS( UUID, - new \Vonage\Voice\NCCO\Action\Talk(TEXT) + $action ); diff --git a/vonage_logo.png b/vonage_logo.png new file mode 100644 index 0000000..755eef3 Binary files /dev/null and b/vonage_logo.png differ