├── .env-example ├── .github └── workflows │ └── push.yml ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── account ├── account-balance.php └── configure-account.php ├── applications ├── create-application.php ├── delete-application.php ├── get-application.php ├── list-applications.php └── update-application.php ├── composer.json ├── config.php ├── conversation ├── conversation │ ├── create-conversation.php │ ├── delete-conversation.php │ ├── get-conversation.php │ ├── list-conversations.php │ └── update-conversations.php ├── event │ ├── create-custom-event.php │ ├── create-event.php │ ├── delete-event.php │ ├── get-event.php │ └── list-events.php ├── member │ ├── create-member.php │ ├── delete-member.php │ ├── get-member.php │ ├── list-members.php │ └── update-member.php └── user │ ├── create-user.php │ ├── delete-user.php │ ├── get-user.php │ ├── list-user-conversations.php │ ├── list-users.php │ └── update-user.php ├── initialize ├── application.php ├── basic.php └── full.php ├── jwt └── decode_incoming_jwt_token.php ├── meetings ├── create-instant-room.php └── create-long-term-room.php ├── messages ├── inbound-message.php ├── message-status.php ├── messenger │ ├── send-audio.php │ ├── send-file.php │ ├── send-image.php │ ├── send-text.php │ └── send-video.php ├── mms │ ├── send-mms-audio.php │ ├── send-mms-vcard.php │ ├── send-mms-video.php │ └── send-mms.php ├── rcs │ ├── revoke-message.php │ ├── send-file.php │ ├── send-image.php │ ├── send-rich-card-carousel.php │ ├── send-rich-card-standalone.php │ ├── send-suggested-action-create-calendar-event.php │ ├── send-suggested-action-dial.php │ ├── send-suggested-action-multiple.php │ ├── send-suggested-action-open-url.php │ ├── send-suggested-action-share-location.php │ ├── send-suggested-action-view-location.php │ ├── send-suggested-reply.php │ ├── send-text.php │ └── send-video.php ├── sandbox │ ├── messenger │ │ └── send-text.php │ ├── viber │ │ └── send-text.php │ └── whatsapp │ │ └── send-text.php ├── signed-webhooks │ └── verify-webhook.php ├── sms │ └── send-sms.php ├── viber │ ├── send-file.php │ ├── send-image.php │ ├── send-text.php │ └── send-video.php └── whatsapp │ ├── mark-as-read.php │ ├── send-audio.php │ ├── send-authentication-template.php │ ├── send-button-link.php │ ├── send-button-quick-reply.php │ ├── send-contact.php │ ├── send-file.php │ ├── send-image.php │ ├── send-location.php │ ├── send-media-mtm.php │ ├── send-mtm.php │ ├── send-multi-product.php │ ├── send-reaction.php │ ├── send-single-product.php │ ├── send-sticker-id.php │ ├── send-sticker-url.php │ ├── send-text.php │ ├── send-unreaction.php │ └── send-video.php ├── network-apis ├── number-verification │ └── verify-phone-number.php └── sim-swap │ ├── check-sim-swap-date.php │ └── check-sim-swap.php ├── number-insights ├── advanced-async-callback │ ├── composer.json │ ├── composer.lock │ └── index.php ├── advanced-async-trigger.php ├── advanced-cnam.php ├── advanced.php ├── basic.php ├── standard-cnam.php └── standard.php ├── numbers ├── cancel.php ├── list-owned.php ├── purchase.php ├── search-available.php └── update.php ├── redact └── transaction.php ├── secret-management ├── create-a-secret.php ├── delete-a-secret.php ├── fetch-secrets.php └── get-a-secret.php ├── sms ├── receive-delivery-receipt-slim │ ├── README.md │ ├── composer.json │ └── index.php ├── receive-delivery-receipt.php ├── receive-sms.php ├── receive-with-slim │ ├── README.md │ ├── composer.json │ └── index.php ├── send-signed-sms.php ├── send-sms-basic.php ├── send-sms.php ├── send-unicode-sms.php ├── send-with-slim │ ├── .env.dist │ ├── README.md │ ├── composer.json │ └── index.php └── verify-signed-sms.php ├── subaccounts ├── create-subaccount.php ├── get-balance-transfers.php ├── get-credit-transfers.php ├── get-subaccount.php ├── get-subaccounts.php ├── reactivate-subaccount.php ├── suspend-subaccount.php ├── transfer-balance.php └── transfer-credit.php ├── verify ├── cancel.php ├── request.php ├── request_with_workflow.php ├── search.php ├── send_psd2_request.php ├── send_psd2_request_with_workflow.php ├── trigger_next_event.php └── verify.php ├── verify2 ├── cancel-request.php ├── check-verification-code.php ├── create-template-fragment.php ├── create-template.php ├── delete-fragment.php ├── delete-template.php ├── get-fragment.php ├── get-template.php ├── list-fragments.php ├── list-templates.php ├── send-request-email.php ├── send-request-silent-auth.php ├── send-request-sms.php ├── send-request-voice.php ├── send-request-whatsapp-interactive.php ├── send-request-whatsapp.php ├── send-request-with-fallback.php ├── update-template-fragment.php └── update-template.php ├── voice ├── README.md ├── conference-call-slim │ ├── composer.json │ └── index.php ├── conference-call.php ├── connect-a-call.php ├── connect-call-slim │ ├── .env.dist │ ├── composer.json │ └── index.php ├── download-a-recording │ └── index.php ├── earmuff-a-call │ └── index.php ├── handle-user-input-with-asr-slim │ ├── README.md │ ├── composer.json │ └── index.php ├── inbound-calls-lumen │ ├── app │ │ ├── Console │ │ │ ├── Commands │ │ │ │ └── .gitkeep │ │ │ └── Kernel.php │ │ └── Exceptions │ │ │ └── Handler.php │ ├── artisan │ ├── bootstrap │ │ └── app.php │ ├── composer.json │ ├── composer.lock │ ├── database │ │ └── .gitkeep │ ├── phpunit.xml │ ├── public │ │ ├── .htaccess │ │ └── index.php │ ├── readme.md │ ├── resources │ │ └── views │ │ │ └── .gitkeep │ ├── routes │ │ └── web.php │ ├── storage │ │ ├── app │ │ │ └── .gitignore │ │ ├── framework │ │ │ ├── cache │ │ │ │ └── .gitignore │ │ │ └── views │ │ │ │ └── .gitignore │ │ └── logs │ │ │ └── .gitignore │ └── tests │ │ ├── ExampleTest.php │ │ └── TestCase.php ├── inbound-calls-slim │ ├── README.md │ ├── composer.json │ └── index.php ├── make-outbound-call-ncco │ └── index.php ├── mute-a-call │ └── index.php ├── play-audio-stream-in-to-call │ └── index.php ├── play-dtmf-in-to-call │ └── index.php ├── play-tts-in-to-call │ └── index.php ├── record-a-call-split-audio │ ├── .env.dist │ ├── composer.json │ └── index.php ├── record-a-call │ ├── .env.dist │ ├── composer.json │ └── index.php ├── record-a-conversation │ ├── .env.dist │ ├── composer.json │ └── index.php ├── record-a-message │ ├── composer.json │ └── index.php ├── retrieve-call-info │ └── index.php ├── retrieve-calls-info │ └── index.php ├── text-to-speech-inbound.php ├── text-to-speech-outbound-lumen │ ├── .env.example │ ├── .gitignore │ ├── app │ │ ├── Console │ │ │ ├── Commands │ │ │ │ └── .gitkeep │ │ │ └── Kernel.php │ │ └── Exceptions │ │ │ └── Handler.php │ ├── artisan │ ├── bootstrap │ │ └── app.php │ ├── composer.json │ ├── composer.lock │ ├── database │ │ └── .gitkeep │ ├── phpunit.xml │ ├── public │ │ ├── .htaccess │ │ └── index.php │ ├── readme.md │ ├── resources │ │ └── views │ │ │ └── .gitkeep │ ├── routes │ │ └── web.php │ ├── storage │ │ ├── app │ │ │ └── .gitignore │ │ ├── framework │ │ │ ├── cache │ │ │ │ └── .gitignore │ │ │ └── views │ │ │ │ └── .gitignore │ │ └── logs │ │ │ └── .gitignore │ └── tests │ │ ├── ExampleTest.php │ │ └── TestCase.php ├── text-to-speech-outbound-slim │ ├── composer.json │ ├── composer.lock │ └── index.php ├── text-to-speech-outbound.php ├── transfer-a-call-with-ncco │ └── index.php ├── transfer-a-call │ └── index.php ├── trigger-notify-action │ ├── README.md │ ├── composer.json │ └── index.php └── user-input-dtmf-slim │ ├── composer.json │ └── index.php └── vonage_logo.png /.env-example: -------------------------------------------------------------------------------- 1 | VONAGE_API_KEY= 2 | VONAGE_API_SECRET= 3 | VONAGE_SIGNATURE_SECRET= 4 | VONAGE_APPLICATION_ID=12a3b4cd-a1b2-1ab2-a1b2-a1234bc5d678 5 | VONAGE_APPLICATION_PRIVATE_KEY_PATH= 6 | FROM= 7 | VONAGE_TO_NUMBER= 8 | RECIPIENT_NUMBER= 9 | TO_NUMBER= 10 | VONAGE_SECRET_ID= 11 | INSIGHT_NUMBER= 12 | SMS_CALLBACK_URL= 13 | 14 | # Numbers API examples 15 | VONAGE_NUMBER=447700900001 16 | VONAGE_NUMBER_TYPE=mobile-lvn 17 | VONAGE_NUMBER_FEATURES=VOICE,SMS 18 | COUNTRY_CODE=GB 19 | NUMBER_SEARCH_PATTERN=1 20 | NUMBER_SEARCH_CRITERIA=234 21 | MESSAGES_APPLICATION_ID=12a3b4cd-a1b2-1ab2-a1b2-a1234bc5d678 22 | VOICE_CALLBACK_TYPE=tel 23 | VOICE_CALLBACK_VALUE=447700900002 24 | VOICE_STATUS_URL=https://example.com/webhooks/status 25 | 26 | # Verify API examples 27 | BRAND_NAME=Acme, Inc. 28 | CODE= 29 | NUMBER= 30 | REQUEST_ID= 31 | WORKFLOW_ID=4 32 | RECIPIENT_NUMBER= 33 | PAYEE_NAME= 34 | AMOUNT= 35 | 36 | # Messages API examples 37 | FB_SENDER_ID= 38 | FB_RECIPIENT_ID= 39 | VIBER_SERVICE_MESSAGE_ID= 40 | WHATSAPP_NUMBER= 41 | WHATSAPP_TEMPLATE_NAMESPACE= 42 | WHATSAPP_TEMPLATE_NAME= 43 | WHATSAPP_AUTH_TEMPLATE_NAME= 44 | WHATSAPP_TEMPLATE_REPLACEMENT_TEXT= 45 | IMAGE_URL= 46 | IMAGE_CAPTION= 47 | FILE_URL= 48 | FILE_CAPTION= 49 | AUDIO_URL= 50 | VIDEO_URL= 51 | 52 | ## For Messages Sandbox 53 | MESSAGES_SANDBOX_URL= 54 | MESSAGES_SANDBOX_WHATSAPP_NUMBER= 55 | MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER= 56 | MESSAGES_SANDBOX_FB_ID= 57 | MESSAGES_SANDBOX_ALLOW_LISTED_FB_RECIPIENT_ID= 58 | MESSAGES_SANDBOX_VIBER_SERVICE_ID= 59 | -------------------------------------------------------------------------------- /.github/workflows/push.yml: -------------------------------------------------------------------------------- 1 | name: Push to Master 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | build: 8 | name: Update NDP Submodule 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Update NDP Submodule 12 | uses: nexmo/github-actions/submodule-auto-pr@main 13 | env: 14 | GH_ADMIN_TOKEN: ${{ secrets.PDX_GH_TOKEN }} 15 | PR_ACTIVE_BRANCH: master 16 | PR_BRANCH_NAME: automated-php-snippets-update 17 | PR_SUBMODULE_PATH: .repos/vonage/vonage-php-code-snippets 18 | PR_TARGET_BRANCH: main 19 | PR_TARGET_ORG: nexmo 20 | PR_TARGET_REPO: nexmo-developer 21 | PR_TITLE: vonage-php-code-snippets Update 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | private.key 3 | .env 4 | composer.lock 5 | .DS_Store 6 | /.idea/codeception.xml 7 | /.idea/deployment.xml 8 | /img.png 9 | /.idea/material_theme_project_new.xml 10 | /.idea/modules.xml 11 | /.idea/php.xml 12 | /.idea/phpspec.xml 13 | /.idea/phpunit.xml 14 | /.idea/symfony2.xml 15 | /.idea/vcs.xml 16 | /.idea/vonage-php-code-snippets.iml 17 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Getting Involved 2 | 3 | Thanks for your interest in the project, we'd love to have you involved! Check out the sections below to find out more about what to do next... 4 | 5 | ## Opening an Issue 6 | 7 | We always welcome issues, if you've seen something that isn't quite right or you have a suggestion for a new feature, please go ahead and open an issue in this project. Include as much information as you have, it really helps. 8 | 9 | ## Making a Code Change 10 | 11 | We're always open to pull requests, but these should be small and clearly described so that we can understand what you're trying to do. Feel free to open an issue first and get some discussion going. 12 | 13 | When you're ready to start coding, fork this repository to your own GitHub account and make your changes in a new branch. Once you're happy, open a pull request and explain what the change is and why you think we should include it in our project. 14 | 15 | 16 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vonage APIs Quickstart Examples for PHP 2 | 3 | Vonage logo 4 | 5 | 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. 6 | 7 | Quickstarts also available for [Java](https://github.com/nexmo/nexmo-java-code-snippets), [.NET](https://github.com/nexmo/nexmo-dotnet-code-snippets), [Node.js](https://github.com/nexmo/nexmo-node-code-snippets), [Python](https://github.com/nexmo/nexmo-python-code-snippets), and [Ruby](https://github.com/nexmo/nexmo-ruby-code-snippets) 8 | 9 | ## Setup 10 | 11 | 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. 12 | 13 | If you would like to run these examples yourself, you will need to do the following: 14 | 15 | 1. Run `composer install` in the root of the repository 16 | 2. Copy `.env-example` to `.env` 17 | 3. Edit `.env` with your Vonage credentials 18 | 19 | From there, you can fill out the various environment variables as detailed by the individual code snippet. Some snippets may share common environment variables. 20 | 21 | Larger or more complex snippets may include their own `composer.json` file and have additional requirements. Please check any READMEs inside of the larger examples for setup instructions. 22 | 23 | ## Configure with Your Vonage API Keys 24 | 25 | 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 26 | the `.env-example` file to `.env` and set the values as required. 27 | 28 | For some of the examples, you will need to [buy a number](https://dashboard.vonage.com/buy-numbers). 29 | 30 | ## Request More Examples 31 | 32 | Please [raise an issue](/../../issues/) to request an example that isn't present within the code snippets. Pull requests will be gratefully received. 33 | 34 | ## Licenses 35 | 36 | - The sample code in this repo is licensed under [Apache2](LICENSE.md) 37 | 38 | -------------------------------------------------------------------------------- /account/account-balance.php: -------------------------------------------------------------------------------- 1 | account()->getBalance(); 9 | echo round($response->getBalance(), 2) . " EUR\n"; 10 | -------------------------------------------------------------------------------- /account/configure-account.php: -------------------------------------------------------------------------------- 1 | account()->updateConfig([ 9 | "sms_callback_url" => SMS_CALLBACK_URL 10 | ]); 11 | print_r($response->toArray()); 12 | -------------------------------------------------------------------------------- /applications/create-application.php: -------------------------------------------------------------------------------- 1 | fromArray([ 12 | 'name' => 'Should Work2', 13 | 'capabilities' => [ 14 | 'voice' => [ 15 | 'webhooks' => [ 16 | 'answer_url' => [ 17 | 'address' => "https://example.com/webhooks/answer", 18 | 'http_method' => "GET" 19 | ], 20 | 'event_url' => [ 21 | 'address' => "https://example.com/webhooks/event", 22 | 'http_method' => "POST" 23 | ] 24 | ] 25 | ], 26 | 'messages' => [ 27 | 'webhooks' => [ 28 | 'inbound_url' => [ 29 | 'address' => "https://example.com/webhooks/inbound", 30 | 'http_method' => "POST" 31 | ], 32 | 'status_url' => [ 33 | 'address' => "https://example.com/webhooks/status", 34 | 'http_method' => "POST" 35 | ] 36 | ] 37 | ], 38 | 'rtc' => [ 39 | 'webhooks' => [ 40 | 'event_url' => [ 41 | 'address' => "https://example.com/webhooks/rtcevent", 42 | 'http_method' => "POST" 43 | ] 44 | ] 45 | ] 46 | ] 47 | ]); 48 | $application = $client->applications()->create($application); 49 | 50 | echo $application->getId() . PHP_EOL; 51 | echo $application->getName() . PHP_EOL; 52 | } catch (\InvalidArgumentException $e) { 53 | echo $e->getMessage() . PHP_EOL; 54 | } 55 | -------------------------------------------------------------------------------- /applications/delete-application.php: -------------------------------------------------------------------------------- 1 | applications()->delete(VONAGE_APPLICATION_ID); 11 | 12 | if ($isDeleted) { 13 | echo "Deleted application " . VONAGE_APPLICATION_ID . PHP_EOL; 14 | } else { 15 | echo "Could not delete application " . VONAGE_APPLICATION_ID . PHP_EOL; 16 | } 17 | } catch (\Vonage\Client\Exception\Request $e) { 18 | echo "There was a problem with the request: " . $e->getMessage() . PHP_EOL; 19 | } catch (\Vonage\Client\Exception\Server $e) { 20 | echo "The server encounted an error: " . $e->getMessage() . PHP_EOL; 21 | } -------------------------------------------------------------------------------- /applications/get-application.php: -------------------------------------------------------------------------------- 1 | applications()->get(VONAGE_APPLICATION_ID); 11 | 12 | echo $application->getId() . PHP_EOL; 13 | echo $application->getName() . PHP_EOL; 14 | } catch (\Vonage\Client\Exception\Request $e) { 15 | echo "There was a problem with the request: " . $e->getMessage() . PHP_EOL; 16 | } catch (\Vonage\Client\Exception\Server $e) { 17 | echo "The server encounted an error: " . $e->getMessage() . PHP_EOL; 18 | } -------------------------------------------------------------------------------- /applications/list-applications.php: -------------------------------------------------------------------------------- 1 | applications() as $application) { 10 | echo sprintf("%s: %s\n", $application->getId(), $application->getName()); 11 | } -------------------------------------------------------------------------------- /applications/update-application.php: -------------------------------------------------------------------------------- 1 | applications()->get(VONAGE_APPLICATION_ID); 11 | $application->setName('New Name2'); 12 | $application->getVoiceConfig()->setWebhook( 13 | Nexmo\Application\VoiceConfig::ANSWER, 14 | new Nexmo\Application\Webhook('http://test.domain/webhook/voice') 15 | ); 16 | $application = $client->applications()->update($application); 17 | 18 | echo $application->getId() . PHP_EOL; 19 | echo $application->getName() . PHP_EOL; 20 | } catch (\InvalidArgumentException $e) { 21 | echo $e->getMessage() . PHP_EOL; 22 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "vonage/client": "^4.0", 4 | "vlucas/phpdotenv": "^2.5", 5 | "lcobucci/jwt": "^4.0", 6 | "ext-json": "*" 7 | } 8 | , 9 | "require-dev": { 10 | "roave/security-advisories": "dev-latest" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | load(); 6 | 7 | foreach($_ENV as $key => $val) { 8 | define($key, $val); 9 | } -------------------------------------------------------------------------------- /conversation/conversation/create-conversation.php: -------------------------------------------------------------------------------- 1 | conversation()->createConversation($createConversationRequest); -------------------------------------------------------------------------------- /conversation/conversation/delete-conversation.php: -------------------------------------------------------------------------------- 1 | conversation()->deleteConversationById(CONVERSATION_ID); -------------------------------------------------------------------------------- /conversation/conversation/get-conversation.php: -------------------------------------------------------------------------------- 1 | conversation()->getConversationById(CONVERSATION_ID); -------------------------------------------------------------------------------- /conversation/conversation/list-conversations.php: -------------------------------------------------------------------------------- 1 | conversation()->listConversations(); -------------------------------------------------------------------------------- /conversation/conversation/update-conversations.php: -------------------------------------------------------------------------------- 1 | CONV_NEW_NAME, 18 | 'display_name' => CONV_NEW_NAME 19 | ]); 20 | 21 | $client->conversation()->updateConversationById(CONVERSATION_ID, $updateConversationRequest); -------------------------------------------------------------------------------- /conversation/event/create-custom-event.php: -------------------------------------------------------------------------------- 1 | 'data' 22 | ] 23 | ); 24 | 25 | $client->conversation()->createEvent($eventRequest); -------------------------------------------------------------------------------- /conversation/event/create-event.php: -------------------------------------------------------------------------------- 1 | conversation()->createEvent($eventRequest); -------------------------------------------------------------------------------- /conversation/event/delete-event.php: -------------------------------------------------------------------------------- 1 | conversation()->deleteEventById(EVENT_ID, CONVERSATION_ID); 17 | -------------------------------------------------------------------------------- /conversation/event/get-event.php: -------------------------------------------------------------------------------- 1 | conversation()->getEventById(EVENT_ID, CONVERSATION_ID); 17 | -------------------------------------------------------------------------------- /conversation/event/list-events.php: -------------------------------------------------------------------------------- 1 | conversation()->delete(CONVERSATION_ID); 17 | -------------------------------------------------------------------------------- /conversation/member/create-member.php: -------------------------------------------------------------------------------- 1 | conversation()->createMember($createMemberRequest, CONVERSATION_ID); 26 | -------------------------------------------------------------------------------- /conversation/member/delete-member.php: -------------------------------------------------------------------------------- 1 | conversation()->deleteMember(MEMBER_ID, CONVERSATION_ID); -------------------------------------------------------------------------------- /conversation/member/get-member.php: -------------------------------------------------------------------------------- 1 | conversation()->getMemberByConversationId(MEMBER_ID, CONVERSATION_ID); -------------------------------------------------------------------------------- /conversation/member/list-members.php: -------------------------------------------------------------------------------- 1 | conversation()->listMembersByConversationId(CONVERSATION_ID); -------------------------------------------------------------------------------- /conversation/member/update-member.php: -------------------------------------------------------------------------------- 1 | conversation()->updateMember($updateMemberRequest); -------------------------------------------------------------------------------- /conversation/user/create-user.php: -------------------------------------------------------------------------------- 1 | USER_NAME, 15 | 'displayName' => USER_DISPLAY_NAME 16 | ]; 17 | 18 | $user = new \Vonage\Users\User(); 19 | $user->fromArray($userData); 20 | 21 | $client->users()->createUser($user); -------------------------------------------------------------------------------- /conversation/user/delete-user.php: -------------------------------------------------------------------------------- 1 | users()->deleteUser(USER_ID); -------------------------------------------------------------------------------- /conversation/user/get-user.php: -------------------------------------------------------------------------------- 1 | users()->getUser(USER_ID); -------------------------------------------------------------------------------- /conversation/user/list-user-conversations.php: -------------------------------------------------------------------------------- 1 | conversation()->listUserConversationsByUserId(USER_ID); -------------------------------------------------------------------------------- /conversation/user/list-users.php: -------------------------------------------------------------------------------- 1 | users()->listUsers(); -------------------------------------------------------------------------------- /conversation/user/update-user.php: -------------------------------------------------------------------------------- 1 | users()->getUser(USER_ID); 14 | $user->setDisplayName(USER_NEW_DISPLAY_NAME); 15 | $user->setName(USER_NEW_NAME); 16 | 17 | $client->users()->updateUser($user); -------------------------------------------------------------------------------- /initialize/application.php: -------------------------------------------------------------------------------- 1 | parser()->parse($token); 18 | try { 19 | $configuration->validator()->validate( 20 | $token, 21 | new \Lcobucci\JWT\Validation\Constraint\SignedWith($configuration->signer(), $configuration->signingKey()) 22 | ); 23 | echo 'Token was validated'; 24 | } catch (\Exception $e) { 25 | var_dump($e->getMessage()); 26 | } 27 | -------------------------------------------------------------------------------- /meetings/create-instant-room.php: -------------------------------------------------------------------------------- 1 | fromArray(['display_name' => ROOM_DISPLAY_NAME]); 12 | $meeting = $client->meetings()->createRoom($room); -------------------------------------------------------------------------------- /meetings/create-long-term-room.php: -------------------------------------------------------------------------------- 1 | fromArray([ 12 | 'display_name' => ROOM_DISPLAY_NAME, 13 | 'type' => 'long_term', 14 | 'expires_at' => '2023-01-30T00:47:04+0000' 15 | ]); 16 | 17 | $meeting = $client->meetings()->createRoom($room); -------------------------------------------------------------------------------- /messages/inbound-message.php: -------------------------------------------------------------------------------- 1 | messages()->send($message); -------------------------------------------------------------------------------- /messages/messenger/send-file.php: -------------------------------------------------------------------------------- 1 | messages()->send($message); -------------------------------------------------------------------------------- /messages/messenger/send-image.php: -------------------------------------------------------------------------------- 1 | messages()->send($message); -------------------------------------------------------------------------------- /messages/messenger/send-text.php: -------------------------------------------------------------------------------- 1 | messages()->send($message); -------------------------------------------------------------------------------- /messages/messenger/send-video.php: -------------------------------------------------------------------------------- 1 | messages()->send($message); -------------------------------------------------------------------------------- /messages/mms/send-mms-audio.php: -------------------------------------------------------------------------------- 1 | messages()->send($mms); 23 | -------------------------------------------------------------------------------- /messages/mms/send-mms-vcard.php: -------------------------------------------------------------------------------- 1 | messages()->send($mms); 23 | -------------------------------------------------------------------------------- /messages/mms/send-mms-video.php: -------------------------------------------------------------------------------- 1 | messages()->send($mms); 23 | -------------------------------------------------------------------------------- /messages/mms/send-mms.php: -------------------------------------------------------------------------------- 1 | messages()->send($mms); 24 | -------------------------------------------------------------------------------- /messages/rcs/revoke-message.php: -------------------------------------------------------------------------------- 1 | messages()->updateRcsStatus($messageUuid, \Vonage\Messages\Client::RCS_STATUS_REVOKED); 16 | -------------------------------------------------------------------------------- /messages/rcs/send-file.php: -------------------------------------------------------------------------------- 1 | messages()->send($rcsFile); 22 | -------------------------------------------------------------------------------- /messages/rcs/send-image.php: -------------------------------------------------------------------------------- 1 | messages()->send($rcsImage); 22 | -------------------------------------------------------------------------------- /messages/rcs/send-rich-card-carousel.php: -------------------------------------------------------------------------------- 1 | [ 18 | "richCard" => [ 19 | "carouselCard" => [ 20 | "cardWidth" => "MEDIUM", 21 | "cardContents" => [ 22 | [ 23 | "title" => "Option 1: Photo", 24 | "description" => "Do you prefer this photo?", 25 | "suggestions" => [ 26 | [ 27 | "reply" => [ 28 | "text" => "Option 1", 29 | "postbackData" => "card_1" 30 | ] 31 | ] 32 | ], 33 | "media" => [ 34 | "height" => "MEDIUM", 35 | "contentInfo" => [ 36 | "fileUrl" => "'\$IMAGE_URL'", 37 | "forceRefresh" => "false" 38 | ] 39 | ] 40 | ], 41 | [ 42 | "title" => "Option 2: Video", 43 | "description" => "Or this video?", 44 | "suggestions" => [ 45 | [ 46 | "reply" => [ 47 | "text" => "Option 2", 48 | "postbackData" => "card_2" 49 | ] 50 | ] 51 | ], 52 | "media" => [ 53 | "height" => "MEDIUM", 54 | "contentInfo" => [ 55 | "fileUrl" => "'\$VIDEO_URL'", 56 | "forceRefresh" => "false" 57 | ] 58 | ] 59 | ] 60 | ] 61 | ] 62 | ] 63 | ] 64 | ] 65 | ); 66 | 67 | $client->messages()->send($rcsCard); 68 | -------------------------------------------------------------------------------- /messages/rcs/send-rich-card-standalone.php: -------------------------------------------------------------------------------- 1 | [ 18 | "richCard" => [ 19 | "standaloneCard" => [ 20 | "thumbnailImageAlignment" => "RIGHT", 21 | "cardOrientation" => "VERTICAL", 22 | "cardContent" => [ 23 | "title" => "Quick question", 24 | "description" => "Do you like this picture?", 25 | "media" => [ 26 | "height" => "TALL", 27 | "contentInfo" => [ 28 | "fileUrl" => "'\$IMAGE_URL'", 29 | "forceRefresh" => "false" 30 | ] 31 | ], 32 | "suggestions" => [ 33 | [ 34 | "reply" => [ 35 | "text" => "Yes", 36 | "postbackData" => "suggestion_1" 37 | ] 38 | ], 39 | [ 40 | "reply" => [ 41 | "text" => "I love it!", 42 | "postbackData" => "suggestion_2" 43 | ] 44 | ] 45 | ] 46 | ] 47 | ] 48 | ] 49 | ] 50 | ] 51 | ); 52 | 53 | $client->messages()->send($rcsCard); 54 | -------------------------------------------------------------------------------- /messages/rcs/send-suggested-action-create-calendar-event.php: -------------------------------------------------------------------------------- 1 | [ 18 | "text" => "Product Launch: Save the date!", 19 | "suggestions" => [ 20 | [ 21 | "action" => [ 22 | "text" => "Save to calendar", 23 | "postbackData" => "postback_data_1234", 24 | "fallbackUrl" => "https://www.google.com/calendar", 25 | "createCalendarEventAction" => [ 26 | "startTime" => "2024-06-28T19:00:00Z", 27 | "endTime" => "2024-06-28T20:00:00Z", 28 | "title" => "Vonage API Product Launch", 29 | "description" => 30 | "Event to demo Vonage\'s new and exciting API product", 31 | ], 32 | ], 33 | ], 34 | ], 35 | ], 36 | ] 37 | ); 38 | 39 | $client->messages()->send($rcsCard); 40 | -------------------------------------------------------------------------------- /messages/rcs/send-suggested-action-dial.php: -------------------------------------------------------------------------------- 1 | [ 18 | "text" => "Call us to claim your free gift!", 19 | "suggestions" => [ 20 | [ 21 | "action" => [ 22 | "text" => "Call now!", 23 | "postbackData" => "postback_data_1234", 24 | "fallbackUrl" => "https://www.example.com/contact/", 25 | "dialAction" => ["phoneNumber" => "+447900000000"], 26 | ], 27 | ], 28 | ], 29 | ], 30 | ] 31 | ); 32 | 33 | $client->messages()->send($rcsCard); 34 | -------------------------------------------------------------------------------- /messages/rcs/send-suggested-action-multiple.php: -------------------------------------------------------------------------------- 1 | [ 18 | "text" => 19 | "Need some help? Call us now or visit our website for more information.", 20 | "suggestions" => [ 21 | [ 22 | "action" => [ 23 | "text" => "Call us", 24 | "postbackData" => "postback_data_1234", 25 | "fallbackUrl" => "https://www.example.com/contact/", 26 | "dialAction" => ["phoneNumber" => "+447900000000"], 27 | ], 28 | ], 29 | [ 30 | "action" => [ 31 | "text" => "Visit site", 32 | "postbackData" => "postback_data_1234", 33 | "openUrlAction" => ["url" => "http://example.com/"], 34 | ], 35 | ], 36 | ], 37 | ], 38 | ] 39 | ); 40 | 41 | $client->messages()->send($rcsCard); 42 | -------------------------------------------------------------------------------- /messages/rcs/send-suggested-action-open-url.php: -------------------------------------------------------------------------------- 1 | [ 18 | "text" => "Check out our latest offers!", 19 | "suggestions" => [ 20 | [ 21 | "action" => [ 22 | "text" => "Open product page", 23 | "postbackData" => "postback_data_1234", 24 | "openUrlAction" => ["url" => "http://example.com/"], 25 | ], 26 | ], 27 | ], 28 | ], 29 | ] 30 | ); 31 | 32 | $client->messages()->send($rcsCard); 33 | -------------------------------------------------------------------------------- /messages/rcs/send-suggested-action-share-location.php: -------------------------------------------------------------------------------- 1 | [ 18 | "text" => 19 | "Your driver will come and meet you at your specified location.", 20 | "suggestions" => [ 21 | [ 22 | "action" => [ 23 | "text" => "Share a location", 24 | "postbackData" => "postback_data_1234", 25 | "shareLocationAction" => [], 26 | ], 27 | ], 28 | ], 29 | ], 30 | ] 31 | ); 32 | 33 | $client->messages()->send($rcsCard); 34 | -------------------------------------------------------------------------------- /messages/rcs/send-suggested-action-view-location.php: -------------------------------------------------------------------------------- 1 | [ 18 | "text" => "Drop by our office!", 19 | "suggestions" => [ 20 | [ 21 | "action" => [ 22 | "text" => "View map", 23 | "postbackData" => "postback_data_1234", 24 | "fallbackUrl" => 25 | "https://www.google.com/maps/place/Vonage/@51.5230371,-0.0852492,15z", 26 | "viewLocationAction" => [ 27 | "latLong" => [ 28 | "latitude" => "51.5230371", 29 | "longitude" => "-0.0852492", 30 | ], 31 | "label" => "Vonage London Office", 32 | ], 33 | ], 34 | ], 35 | ], 36 | ], 37 | ] 38 | ); 39 | 40 | $client->messages()->send($rcsCard); 41 | -------------------------------------------------------------------------------- /messages/rcs/send-suggested-reply.php: -------------------------------------------------------------------------------- 1 | [ 18 | "text" => "What do you think of Vonage APIs?", 19 | "suggestions" => [ 20 | [ 21 | "reply" => [ 22 | "text" => "They\'re great!", 23 | "postbackData" => "suggestion_1", 24 | ], 25 | ], 26 | [ 27 | "reply" => [ 28 | "text" => "They\'re awesome!", 29 | "postbackData" => "suggestion_2", 30 | ], 31 | ], 32 | ], 33 | ], 34 | ] 35 | ); 36 | 37 | $client->messages()->send($rcsCard); 38 | -------------------------------------------------------------------------------- /messages/rcs/send-text.php: -------------------------------------------------------------------------------- 1 | messages()->send($rcsText); 20 | -------------------------------------------------------------------------------- /messages/rcs/send-video.php: -------------------------------------------------------------------------------- 1 | messages()->send($rcsImage); 22 | -------------------------------------------------------------------------------- /messages/sandbox/messenger/send-text.php: -------------------------------------------------------------------------------- 1 | MESSAGES_SANDBOX_URL 14 | ] 15 | ); 16 | 17 | $message = new \Vonage\Messages\MessageType\Messenger\MessengerText( 18 | MESSAGES_SANDBOX_ALLOW_LISTED_FB_RECIPIENT_ID, 19 | MESSAGES_SANDBOX_FB_ID, 20 | 'This is a Messenger text message sent using the Vonage PHP SDK via the Messages Sandbox' 21 | ); 22 | 23 | $response = $client->messages()->send($message); 24 | -------------------------------------------------------------------------------- /messages/sandbox/viber/send-text.php: -------------------------------------------------------------------------------- 1 | MESSAGES_SANDBOX_URL 14 | ] 15 | ); 16 | 17 | $viber = new \Vonage\Messages\MessageType\Viber\ViberText( 18 | MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER, 19 | MESSAGES_SANDBOX_VIBER_SERVICE_ID, 20 | 'This is a Viber text message sent using the Vonage PHP SDK via the Messages Sandbox' 21 | ); 22 | 23 | $response = $client->messages()->send($message); 24 | -------------------------------------------------------------------------------- /messages/sandbox/whatsapp/send-text.php: -------------------------------------------------------------------------------- 1 | MESSAGES_SANDBOX_URL 14 | ] 15 | ); 16 | 17 | $whatsApp = new \Vonage\Messages\MessageType\WhatsApp\WhatsAppText( 18 | MESSAGES_SANDBOX_ALLOW_LISTED_TO_NUMBER, 19 | MESSAGES_SANDBOX_WHATSAPP_NUMBER, 20 | 'This is a WhatsApp text message sent using the Vonage PHP SDK via the Messages Sandbox via the Messages Sandbox' 21 | ); 22 | 23 | $response = $client->messages()->send($message); 24 | -------------------------------------------------------------------------------- /messages/signed-webhooks/verify-webhook.php: -------------------------------------------------------------------------------- 1 | sms()->send($message); 15 | 16 | // Incoming Request 17 | $signature = new Vonage\Client\Signature($_GET, VONAGE_SIGNATURE_SECRET, 'sha256'); 18 | $isValid = $signature->check($_GET['sig']); 19 | -------------------------------------------------------------------------------- /messages/sms/send-sms.php: -------------------------------------------------------------------------------- 1 | messages()->send($viber); -------------------------------------------------------------------------------- /messages/viber/send-image.php: -------------------------------------------------------------------------------- 1 | messages()->send($viber); -------------------------------------------------------------------------------- /messages/viber/send-text.php: -------------------------------------------------------------------------------- 1 | messages()->send($viber); -------------------------------------------------------------------------------- /messages/viber/send-video.php: -------------------------------------------------------------------------------- 1 | messages()->send($viber); -------------------------------------------------------------------------------- /messages/whatsapp/mark-as-read.php: -------------------------------------------------------------------------------- 1 | messages()->getAPIResource()->setBaseUrl('https://api-eu.nexmo.com/v1'); 12 | 13 | $client->messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-audio.php: -------------------------------------------------------------------------------- 1 | messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-authentication-template.php: -------------------------------------------------------------------------------- 1 | TO_NUMBER, 14 | "from" => WHATSAPP_NUMBER, 15 | "channel" => "whatsapp", 16 | "message_type" => "custom", 17 | "custom" => [ 18 | "type" => "template", 19 | "template" => [ 20 | "name" => WHATSAPP_AUTH_TEMPLATE_NAME, 21 | "language" => [ 22 | "policy" => "deterministic", 23 | "code" => "en" 24 | ], 25 | "components" => [ 26 | [ 27 | "type" => "body", 28 | "parameters" => [ 29 | [ 30 | "type" => "text", 31 | "text" => '$OTP' 32 | ] 33 | ] 34 | ], 35 | [ 36 | "type" => "button", 37 | "sub_type" => "url", 38 | "index" => "0", 39 | "parameters" => [ 40 | [ 41 | "type" => "text", 42 | "text" => '$OTP' 43 | ] 44 | ] 45 | ] 46 | ] 47 | ] 48 | ] 49 | ]; 50 | 51 | 52 | $whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( 53 | TO_NUMBER, 54 | FROM_NUMBER, 55 | $custom 56 | ); 57 | 58 | $client->messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-button-link.php: -------------------------------------------------------------------------------- 1 | "template", 14 | "template" => [ 15 | "namespace" => WHATSAPP_TEMPLATE_NAMESPACE, 16 | "name" => WHATSAPP_TEMPLATE_NAME, 17 | "language" => ["code" => "en", "policy" => "deterministic"], 18 | "components" => [ 19 | [ 20 | "type" => "header", 21 | "parameters" => [ 22 | [ 23 | "type" => "image", 24 | "image" => ["link" => HEADER_IMAGE_URL], 25 | ], 26 | ], 27 | ], 28 | [ 29 | "type" => "body", 30 | "parameters" => [ 31 | ["type" => "text", "text" => "Anand"], 32 | ["type" => "text", "text" => "Quest"], 33 | ["type" => "text", "text" => "113-0921387"], 34 | ["type" => "text", "text" => "23rd Nov 2019"], 35 | ], 36 | ], 37 | [ 38 | "type" => "button", 39 | "index" => "0", 40 | "sub_type" => "url", 41 | "parameters" => [ 42 | ["type" => "text", "text" => "1Z999AA10123456784"], 43 | ], 44 | ], 45 | ], 46 | ], 47 | ]; 48 | 49 | $whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( 50 | TO_NUMBER, 51 | FROM_NUMBER, 52 | $custom 53 | ); 54 | 55 | $client->messages()->send($whatsApp); 56 | -------------------------------------------------------------------------------- /messages/whatsapp/send-button-quick-reply.php: -------------------------------------------------------------------------------- 1 | "template", 14 | "template" => [ 15 | "namespace" => WHATSAPP_TEMPLATE_NAMESPACE, 16 | "name" => WHATSAPP_TEMPLATE_NAME, 17 | "language" => ["code" => "en", "policy" => "deterministic"], 18 | "components" => [ 19 | [ 20 | "type" => "header", 21 | "parameters" => [["type" => "text", "text" => "12/26"]], 22 | ], 23 | [ 24 | "type" => "body", 25 | "parameters" => [ 26 | ["type" => "text", "text" => "*Ski Trip*"], 27 | ["type" => "text", "text" => "2019-12-26"], 28 | [ 29 | "type" => "text", 30 | "text" => "*Squaw Valley Ski Resort, Tahoe*", 31 | ], 32 | ], 33 | ], 34 | [ 35 | "type" => "button", 36 | "sub_type" => "quick_reply", 37 | "index" => 0, 38 | "parameters" => [ 39 | ["type" => "payload", "payload" => "Yes-Button-Payload"], 40 | ], 41 | ], 42 | [ 43 | "type" => "button", 44 | "sub_type" => "quick_reply", 45 | "index" => 1, 46 | "parameters" => [ 47 | ["type" => "payload", "payload" => "No-Button-Payload"], 48 | ], 49 | ], 50 | ], 51 | ], 52 | ]; 53 | 54 | $whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( 55 | TO_NUMBER, 56 | FROM_NUMBER, 57 | $custom 58 | ); 59 | 60 | $client->messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-contact.php: -------------------------------------------------------------------------------- 1 | "contacts", 14 | "contacts" => [ 15 | [ 16 | "addresses" => [ 17 | [ 18 | "city" => "Menlo Park", 19 | "country" => "United States", 20 | "country_code" => "us", 21 | "state" => "CA", 22 | "street" => "1 Hacker Way", 23 | "type" => "HOME", 24 | "zip" => "94025", 25 | ], 26 | [ 27 | "city" => "Menlo Park", 28 | "country" => "United States", 29 | "country_code" => "us", 30 | "state" => "CA", 31 | "street" => "200 Jefferson Dr", 32 | "type" => "WORK", 33 | "zip" => "94025", 34 | ], 35 | ], 36 | "birthday" => "2012-08-18", 37 | "emails" => [ 38 | ["email" => "test@fb.com", "type" => "WORK"], 39 | ["email" => "test@whatsapp.com", "type" => "WORK"], 40 | ], 41 | "name" => [ 42 | "first_name" => "John", 43 | "formatted_name" => "John Smith", 44 | "last_name" => "Smith", 45 | ], 46 | "org" => [ 47 | "company" => "WhatsApp", 48 | "department" => "Design", 49 | "title" => "Manager", 50 | ], 51 | "phones" => [ 52 | ["phone" => "+1 (940) 555-1234", "type" => "HOME"], 53 | [ 54 | "phone" => "+1 (650) 555-1234", 55 | "type" => "WORK", 56 | "wa_id" => "16505551234", 57 | ], 58 | ], 59 | "urls" => [["url" => "https://www.facebook.com", "type" => "WORK"]], 60 | ], 61 | ], 62 | ]; 63 | 64 | $whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( 65 | TO_NUMBER, 66 | FROM_NUMBER, 67 | $custom 68 | ); 69 | 70 | $client->messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-file.php: -------------------------------------------------------------------------------- 1 | messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-image.php: -------------------------------------------------------------------------------- 1 | messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-location.php: -------------------------------------------------------------------------------- 1 | "location", 14 | "location" => [ 15 | "longitude" => -122.425332, 16 | "latitude" => 37.758056, 17 | "name" => "Facebook HQ", 18 | "address" => "1 Hacker Way, Menlo Park, CA 94025", 19 | ], 20 | ]; 21 | 22 | $whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( 23 | TO_NUMBER, 24 | FROM_NUMBER, 25 | $custom 26 | ); 27 | 28 | $client->messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-media-mtm.php: -------------------------------------------------------------------------------- 1 | "template", 14 | "template" => [ 15 | "name" => WHATSAPP_TEMPLATE_NAME, 16 | "language" => ["policy" => "deterministic", "code" => "en"], 17 | "components" => [ 18 | [ 19 | "type" => "header", 20 | "parameters" => [ 21 | [ 22 | "type" => "image", 23 | "image" => [ 24 | "link" => IMAGE_URL, 25 | ], 26 | ], 27 | ], 28 | ], 29 | [ 30 | "type" => "body", 31 | "parameters" => [ 32 | "type" => "text", 33 | "text" => WHATSAPP_TEMPLATE_REPLACEMENT_TEXT, 34 | ], 35 | ], 36 | ], 37 | ], 38 | ]; 39 | 40 | $whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( 41 | TO_NUMBER, 42 | FROM_NUMBER, 43 | $custom 44 | ); 45 | 46 | $client->messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-mtm.php: -------------------------------------------------------------------------------- 1 | WHATSAPP_TEMPLATE_NAMESPACE . ":" . WHATSAPP_TEMPLATE_NAME, 14 | "parameters" => [ 15 | "Vonage Verification", 16 | "64873", 17 | "10", 18 | ], 19 | ]; 20 | 21 | $whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( 22 | TO_NUMBER, 23 | FROM_NUMBER, 24 | $custom 25 | ); 26 | 27 | $client->messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-multi-product.php: -------------------------------------------------------------------------------- 1 | "interactive", 14 | "interactive" => [ 15 | "type" => "product_list", 16 | "header" => [ 17 | "type" => "text", 18 | "text" => "Our top products" 19 | ], 20 | "body" => [ 21 | "text" => "Check out these great products" 22 | ], 23 | "footer" => [ 24 | "text" => "Sale now on!" 25 | ], 26 | "action" => [ 27 | "catalog_id" => CATALOG_ID, 28 | "sections" => [ 29 | [ 30 | "title" => "Cool products", 31 | "product_items" => [ 32 | ["product_retailer_id" => PRODUCT_ID], 33 | ["product_retailer_id" => PRODUCT_ID] 34 | ] 35 | ], 36 | [ 37 | "title" => "Awesome products", 38 | "product_items" => [ 39 | ["product_retailer_id" => PRODUCT_ID] 40 | ] 41 | ] 42 | ] 43 | ] 44 | ] 45 | ]; 46 | 47 | $whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( 48 | TO_NUMBER, 49 | FROM_NUMBER, 50 | $custom 51 | ); 52 | 53 | $client->messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-reaction.php: -------------------------------------------------------------------------------- 1 | "reaction", 14 | "reaction" => [ 15 | "action" => "react", 16 | "emoji" => EMOJI 17 | ], 18 | "context" => [ 19 | "message_uuid" => MESSAGE_UUID 20 | ], 21 | "to" => TO_NUMBER, 22 | "from" => WHATSAPP_NUMBER, 23 | "channel" => "whatsapp" 24 | ]; 25 | 26 | $whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( 27 | TO_NUMBER, 28 | FROM_NUMBER, 29 | $custom 30 | ); 31 | 32 | $client->messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-single-product.php: -------------------------------------------------------------------------------- 1 | TO_NUMBER, 14 | "from" => WHATSAPP_NUMBER, 15 | "channel" => "whatsapp", 16 | "message_type" => "custom", 17 | "custom" => [ 18 | "type" => "interactive", 19 | "interactive" => [ 20 | "type" => "product", 21 | "body" => [ 22 | "text" => "Check out this cool product" 23 | ], 24 | "footer" => [ 25 | "text" => "Sale now on!" 26 | ], 27 | "action" => [ 28 | "catalog_id" => CATALOG_ID, 29 | "product_retailer_id" => PRODUCT_ID 30 | ] 31 | ] 32 | ] 33 | ]; 34 | 35 | $whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( 36 | TO_NUMBER, 37 | FROM_NUMBER, 38 | $custom 39 | ); 40 | 41 | $client->messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-sticker-id.php: -------------------------------------------------------------------------------- 1 | "sticker", 14 | "sticker" => [ 15 | "id" => STICKER_ID 16 | ], 17 | "to" => TO_NUMBER, 18 | "from" => WHATSAPP_NUMBER, 19 | "channel" => "whatsapp" 20 | ]; 21 | 22 | 23 | $whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( 24 | TO_NUMBER, 25 | FROM_NUMBER, 26 | $custom 27 | ); 28 | 29 | $client->messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-sticker-url.php: -------------------------------------------------------------------------------- 1 | "sticker", 14 | "sticker" => [ 15 | "url" => STICKER_URL 16 | ], 17 | "to" => TO_NUMBER, 18 | "from" => WHATSAPP_NUMBER, 19 | "channel" => "whatsapp" 20 | ]; 21 | 22 | 23 | $whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( 24 | TO_NUMBER, 25 | FROM_NUMBER, 26 | $custom 27 | ); 28 | 29 | $client->messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-text.php: -------------------------------------------------------------------------------- 1 | messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-unreaction.php: -------------------------------------------------------------------------------- 1 | "reaction", 14 | "reaction" => [ 15 | "action" => "unreact" 16 | ], 17 | "context" => [ 18 | "message_uuid" => MESSAGE_UUID 19 | ], 20 | "to" => TO_NUMBER, 21 | "from" => WHATSAPP_NUMBER, 22 | "channel" => "whatsapp" 23 | ]; 24 | 25 | $whatsApp = new \Vonage\Messages\Channel\WhatsApp\WhatsAppCustom( 26 | TO_NUMBER, 27 | FROM_NUMBER, 28 | $custom 29 | ); 30 | 31 | $client->messages()->send($whatsApp); -------------------------------------------------------------------------------- /messages/whatsapp/send-video.php: -------------------------------------------------------------------------------- 1 | messages()->send($whatsApp); -------------------------------------------------------------------------------- /network-apis/number-verification/verify-phone-number.php: -------------------------------------------------------------------------------- 1 | numberVerification()->verifyNumber(PHONE_NUMBER); -------------------------------------------------------------------------------- /network-apis/sim-swap/check-sim-swap-date.php: -------------------------------------------------------------------------------- 1 | simswap()->checkSimSwapDate(PHONE_NUMBER); -------------------------------------------------------------------------------- /network-apis/sim-swap/check-sim-swap.php: -------------------------------------------------------------------------------- 1 | simswap()->checkSimSwap(PHONE_NUMBER); -------------------------------------------------------------------------------- /number-insights/advanced-async-callback/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "slim/slim": "^3.8" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /number-insights/advanced-async-callback/index.php: -------------------------------------------------------------------------------- 1 | getParsedBody(); 11 | 12 | error_log($params['status_message']); 13 | error_log($params['country_code']); 14 | error_log($params['current_carrier']['name']); 15 | 16 | return $response->withStatus(204); 17 | }; 18 | 19 | $app->post('/webhooks/insight', $handler); 20 | $app->run(); 21 | -------------------------------------------------------------------------------- /number-insights/advanced-async-trigger.php: -------------------------------------------------------------------------------- 1 | ] [-c ] 15 | 16 | -n Telephone number to run Insights against. Must be international format 17 | -c URL to post the Insight results to 18 | 19 | You may also set the environment variables SEARCH_NUMBER and CALLBACK_WEBHOOK 20 | 21 | ENDHELP; 22 | 23 | if (array_key_exists('h', $options)) { 24 | echo $helpText . PHP_EOL; 25 | exit(1); 26 | } 27 | 28 | if (!defined('SEARCH_NUMBER')) { 29 | define('SEARCH_NUMBER', (array_key_exists('n', $options)) ? $options['n'] : null); 30 | } 31 | 32 | if (!defined('CALLBACK_WEBHOOK')) { 33 | define('CALLBACK_WEBHOOK', (array_key_exists('c', $options)) ? $options['c'] : null); 34 | } 35 | 36 | if (is_null(SEARCH_NUMBER) || is_null(CALLBACK_WEBHOOK)) { 37 | echo "Please supply both a search number and a callback address" 38 | . PHP_EOL 39 | . PHP_EOL 40 | . $helpText 41 | ; 42 | exit(1); 43 | } 44 | 45 | try { 46 | $client->insights()->advancedAsync(SEARCH_NUMBER, CALLBACK_WEBHOOK); 47 | echo "The number will be looked up soon."; 48 | } catch (\Vonage\Client\Exception\Request $e) { 49 | error_log("Client error: " . $e->getMessage()); 50 | exit(1); 51 | } catch (\Vonage\Client\Exception\Server $e) { 52 | error_log("Server error: " . $e->getMessage()); 53 | exit(1); 54 | } 55 | -------------------------------------------------------------------------------- /number-insights/advanced-cnam.php: -------------------------------------------------------------------------------- 1 | insights()->advancedCnam(INSIGHT_NUMBER); 9 | 10 | switch($insights->getReachable()) { 11 | case 'reachable': 12 | $reachableStatus = 'is reachable'; 13 | break; 14 | case 'unknown': 15 | $reachableStatus = 'may be reachable'; 16 | break; 17 | default: 18 | $reachableStatus = 'could not be queried'; 19 | } 20 | 21 | echo "The number ".$insights->getNationalFormatNumber()." ". $reachableStatus.", and is owned by ".$insights->getCallerName(); 22 | -------------------------------------------------------------------------------- /number-insights/advanced.php: -------------------------------------------------------------------------------- 1 | insights()->advanced(INSIGHT_NUMBER); 9 | 10 | switch($insights->getReachable()) { 11 | case 'reachable': 12 | $reachableStatus = 'is reachable'; 13 | break; 14 | case 'unknown': 15 | $reachableStatus = 'may be reachable'; 16 | break; 17 | default: 18 | $reachableStatus = 'could not be queried'; 19 | } 20 | 21 | echo "The number ".$insights->getNationalFormatNumber()." ". $reachableStatus; 22 | -------------------------------------------------------------------------------- /number-insights/basic.php: -------------------------------------------------------------------------------- 1 | insights()->basic(INSIGHT_NUMBER); 9 | 10 | echo "The number ".$insights->getNationalFormatNumber()." is located in " . $insights->getCountryName(); 11 | -------------------------------------------------------------------------------- /number-insights/standard-cnam.php: -------------------------------------------------------------------------------- 1 | insights()->standardCnam(INSIGHT_NUMBER); 9 | 10 | echo "The number ".$insights->getNationalFormatNumber()." is registered to the network " . $insights->getCurrentCarrier()['name'].", and is owned by ".$insights->getCallerName(); 11 | -------------------------------------------------------------------------------- /number-insights/standard.php: -------------------------------------------------------------------------------- 1 | insights()->standard(INSIGHT_NUMBER); 9 | 10 | echo "The number ".$insights->getNationalFormatNumber()." is registered to the network " . $insights->getCurrentCarrier()['name']; 11 | -------------------------------------------------------------------------------- /numbers/cancel.php: -------------------------------------------------------------------------------- 1 | numbers()->cancel(VONAGE_NUMBER); 10 | echo "Number cancelled"; 11 | } 12 | 13 | catch(Exception $e) { 14 | echo "Error cancelling number"; 15 | } -------------------------------------------------------------------------------- /numbers/list-owned.php: -------------------------------------------------------------------------------- 1 | setPattern((int) NUMBER_SEARCH_CRITERIA) 13 | ->setSearchPattern((int) NUMBER_SEARCH_PATTERN) 14 | ; 15 | $response = $client->numbers()->searchOwned($filter); 16 | 17 | echo count($response). " of your numbers match:\n"; 18 | 19 | foreach($response as $number) { 20 | echo "Tel: " . $number->getMsisdn() . " Type: " . $number->getType() . "\n"; 21 | } 22 | } catch (\Exception $e) { 23 | echo $e->getMessage(); 24 | } 25 | -------------------------------------------------------------------------------- /numbers/purchase.php: -------------------------------------------------------------------------------- 1 | numbers()->purchase(VONAGE_NUMBER, COUNTRY_CODE); 10 | echo "Number purchased"; 11 | } catch (Exception $e) { 12 | echo "Error purchasing number"; 13 | } -------------------------------------------------------------------------------- /numbers/search-available.php: -------------------------------------------------------------------------------- 1 | (string) NUMBER_SEARCH_CRITERIA, 14 | "search_pattern" => (int) NUMBER_SEARCH_PATTERN, 15 | "type" => VONAGE_NUMBER_TYPE, 16 | "features" => VONAGE_NUMBER_FEATURES, 17 | ]); 18 | $response = $client->numbers()->searchAvailable(COUNTRY_CODE, $filter); 19 | 20 | echo "There are " . count($response) . " matching numbers available for purchase:\n"; 21 | 22 | foreach ($response as $number) { 23 | echo "Tel: " . $number->getMsisdn() . " Cost: " . $number->getCost() . "\n"; 24 | } 25 | -------------------------------------------------------------------------------- /numbers/update.php: -------------------------------------------------------------------------------- 1 | numbers()->get(VONAGE_NUMBER); 11 | $number->setAppId(VONAGE_APPLICATION_ID); 12 | $client->numbers()->update($number); 13 | echo "Number updated" . PHP_EOL; 14 | 15 | } catch (Exception $e) { 16 | echo "Error updating number" . PHP_EOL; 17 | } 18 | -------------------------------------------------------------------------------- /redact/transaction.php: -------------------------------------------------------------------------------- 1 | redact()->transaction(VONAGE_REDACT_ID, VONAGE_REDACT_TYPE); 10 | -------------------------------------------------------------------------------- /secret-management/create-a-secret.php: -------------------------------------------------------------------------------- 1 | account()->createSecret(VONAGE_API_KEY, $secret); 11 | 12 | -------------------------------------------------------------------------------- /secret-management/delete-a-secret.php: -------------------------------------------------------------------------------- 1 | account()->deleteSecret(VONAGE_API_KEY, VONAGE_SECRET_ID); 10 | echo "OK\n"; 11 | } catch(\Vonage\Client\Exception\Request $e) { 12 | echo $e->getMessage(); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /secret-management/fetch-secrets.php: -------------------------------------------------------------------------------- 1 | account()->listSecrets(VONAGE_API_KEY); 9 | /** @var \Vonage\Account\Secret $secret */ 10 | foreach($secretsCollection->getSecrets() as $secret) { 11 | echo "ID: " . $secret->getId() . " (created " . $secret->getCreatedAt() .")\n"; 12 | } 13 | -------------------------------------------------------------------------------- /secret-management/get-a-secret.php: -------------------------------------------------------------------------------- 1 | account()->getSecret(VONAGE_API_KEY, VONAGE_SECRET_ID); 10 | echo "ID: " . $secret->getId() . " (created " . $secret->getCreatedAt() .")\n"; 11 | } catch (\Vonage\Client\Exception\Request $e) { 12 | echo $e->getMessage(); 13 | } 14 | -------------------------------------------------------------------------------- /sms/receive-delivery-receipt-slim/README.md: -------------------------------------------------------------------------------- 1 | ### Usage 2 | 3 | This quick demo shows how to generate a delivery receipt from an incoming request. 4 | 5 | To run this demo: 6 | 7 | 1. Run `composer install` 8 | 2. Start the web server `composer run --timeout=0 serve` 9 | 3. Start ngrok with `ngrok http 3000`. ngrok will give you a forwarding address you can now use for your delivery receipts. 10 | 4. Copy this URL and go to your [customer dashboard](https://dashboard.nexmo.com/sign-in) 11 | 5. Click on your name, then go to ["Settings"](https://dashboard.nexmo.com/settings) 12 | 6. Under the "Default SMS Setting", change the "Delivery Receipts" option to `https://your-ngrok-url/webhooks/delivery-receipt` 13 | 7. Click "Save Changes" 14 | 15 | You can now send an SMS, and delivery receipts will be fowarded to this ngrok 16 | URL. You can check the console output of the server to see the delivery 17 | receipt information. 18 | -------------------------------------------------------------------------------- /sms/receive-delivery-receipt-slim/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "slim/slim": "^3.8", 4 | "vonage/client": "^2.3" 5 | }, 6 | "scripts":{ 7 | "serve": "php -S 0.0.0.0:3000 index.php" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /sms/receive-delivery-receipt-slim/index.php: -------------------------------------------------------------------------------- 1 | withStatus(204); 15 | }; 16 | 17 | $app->map(['GET', 'POST'], '/webhooks/delivery-receipt', $handler); 18 | 19 | $app->run(); 20 | -------------------------------------------------------------------------------- /sms/receive-delivery-receipt.php: -------------------------------------------------------------------------------- 1 | getText()); 13 | $client->sms()->send( 14 | new \Vonage\SMS\Message\SMS($inbound->getFrom(), $inbound->getTo(), 'Thanks for sending a message!' ) 15 | ); 16 | -------------------------------------------------------------------------------- /sms/receive-with-slim/README.md: -------------------------------------------------------------------------------- 1 | ### Usage 2 | 3 | This quick demo shows how to receive an inbound SMS message. 4 | 5 | To run this demo: 6 | 7 | 1. Run `composer install` 8 | 2. Start the web server `composer run --timeout=0 serve` 9 | 3. Start ngrok with `ngrok http 3000`. ngrok will give you a forwarding address you can now use for your messages. 10 | 4. Copy this URL and go to your [customer dashboard](https://dashboard.nexmo.com/sign-in) 11 | 5. Click on "Numbers", then ["Your Numbers"](https://dashboard.nexmo.com/your-numbers) 12 | 6. Click the "Edit" icon for the number you want to receive the SMS message 13 | 6. Under the "SMS" section, change the "Inbound Webhook URL" option to `https://your-ngrok-url/webhooks/webhooks/inbound-sms` 14 | 7. Click "Save" 15 | 16 | You can now send an SMS to the number you just configured, and the message will 17 | be forwarded to the webhook URL. You can view the console output to see the 18 | message information. 19 | -------------------------------------------------------------------------------- /sms/receive-with-slim/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "slim/slim": "4.*", 4 | "vonage/client": "^2.4" 5 | }, 6 | "scripts":{ 7 | "serve": "php -S 0.0.0.0:3000 index.php" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /sms/receive-with-slim/index.php: -------------------------------------------------------------------------------- 1 | getMsisdn() . ' message: ' . $sms->getText()); 13 | 14 | return $response->withStatus(204); 15 | }; 16 | 17 | $app->map(['GET', 'POST'], '/webhooks/inbound-sms', $handler); 18 | 19 | $app->run(); 20 | -------------------------------------------------------------------------------- /sms/send-signed-sms.php: -------------------------------------------------------------------------------- 1 | sms()->send( 14 | new \Vonage\SMS\Message\SMS(TO_NUMBER, FROM_NUMBER, 'Super interesting message') 15 | ); 16 | 17 | echo "Message status: " . $response->current()->getStatus() . "\n"; 18 | -------------------------------------------------------------------------------- /sms/send-sms-basic.php: -------------------------------------------------------------------------------- 1 | sms()->send( 10 | new \Vonage\SMS\Message\SMS(TO_NUMBER, BRAND_NAME, 'A text message sent using the Vonage SMS API') 11 | ); 12 | 13 | $message = $response->current(); 14 | 15 | if ($message->getStatus() == 0) { 16 | echo "The message was sent successfully\n"; 17 | } else { 18 | echo "The message failed with status: " . $message->getStatus() . "\n"; 19 | } 20 | -------------------------------------------------------------------------------- /sms/send-sms.php: -------------------------------------------------------------------------------- 1 | sms()->send( 10 | new \Vonage\SMS\Message\SMS(TO_NUMBER, BRAND_NAME, 'A text message sent using the Vonage SMS API') 11 | ); 12 | 13 | $message = $response->current(); 14 | 15 | if ($message->getStatus() == 0) { 16 | echo "The message was sent successfully\n"; 17 | } else { 18 | echo "The message failed with status: " . $message->getStatus() . "\n"; 19 | } 20 | -------------------------------------------------------------------------------- /sms/send-unicode-sms.php: -------------------------------------------------------------------------------- 1 | sms()->send( 10 | new \Vonage\SMS\Message\SMS(TO_NUMBER, BRAND_NAME, 'こんにちは世界', 'unicode') 11 | ); -------------------------------------------------------------------------------- /sms/send-with-slim/.env.dist: -------------------------------------------------------------------------------- 1 | VONAGE_API_KEY= 2 | VONAGE_API_SECRET= 3 | VONAGE_NUMBER= -------------------------------------------------------------------------------- /sms/send-with-slim/README.md: -------------------------------------------------------------------------------- 1 | # Sending an SMS with Slim and Nexmo 2 | 3 | Here is a very simple example to show how you can send an SMS from Slim, using Nexmo's API. If you're new to Nexmo, try our [getting started guide](https://developer.nexmo.com/messaging/sms/overview#getting-started) for SMS before diving into this lightweight example. 4 | 5 | ## Usage 6 | 7 | * If you haven't already, at the top level of this repository: Copy `.env.dist` to `.env` and add your own values. 8 | * Install the dependencies with `composer install`. 9 | * Start the PHP webserver from the current directory (where this README is) with this command: `php -S localhost:8080`. 10 | * Send a `POST` request to `http://localhost:8080/sms/[PHONE_NUMBER]` with a body parameter `text` containing the message to send 11 | 12 | Here's an example curl command: 13 | 14 | ``` 15 | curl http://localhost:8080/sms/442079460000 -d text="Have a nice day" 16 | ``` 17 | -------------------------------------------------------------------------------- /sms/send-with-slim/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "vonage/client": "^2.3", 4 | "slim/slim": "^4.0", 5 | "vlucas/phpdotenv": "^4.0" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /sms/send-with-slim/index.php: -------------------------------------------------------------------------------- 1 | load(); 15 | 16 | $app = AppFactory::create(); 17 | $app->addErrorMiddleware(true, true, true); 18 | $app->addBodyParsingMiddleware(); 19 | 20 | $app->post('/sms/{number}', function (ServerRequestInterface $request, ResponseInterface $response, $args) { 21 | $body = $request->getParsedBody(); 22 | 23 | if (!isset($body['text'])) { 24 | $response->withStatus(400)->getBody()->write('No message provided'); 25 | return $response; 26 | } 27 | 28 | $client = new Client(new Basic(getenv('VONAGE_API_KEY'), getenv('VONAGE_API_SECRET'))); 29 | $text = new SMS($args['number'], getenv('VONAGE_NUMBER'), $body['text']); 30 | $client->sms()->send($text); 31 | $response->getBody()->write("Sending an SMS to " . $args['number']); 32 | return $response; 33 | }); 34 | 35 | $app->run(); 36 | -------------------------------------------------------------------------------- /sms/verify-signed-sms.php: -------------------------------------------------------------------------------- 1 | isValid()) { 8 | $params = $inbound->getRequestData(); 9 | $signature = new Vonage\Client\Signature( 10 | $params, 11 | VONAGE_API_SIGNATURE_SECRET, 12 | 'md5hash' 13 | ); 14 | $validSig = $signature->check($params['sig']); 15 | 16 | if($validSig) { 17 | error_log("Valid signature"); 18 | } else { 19 | error_log("Invalid signature"); 20 | } 21 | 22 | } else { 23 | error_log('Invalid message'); 24 | } 25 | -------------------------------------------------------------------------------- /subaccounts/create-subaccount.php: -------------------------------------------------------------------------------- 1 | setName(NEW_SUBACCOUNT_NAME); 11 | $account->setSecret(NEW_SUBACCOUNT_SECRET); 12 | 13 | $client->subaccount()->createSubaccount(VONAGE_API_KEY, $account); -------------------------------------------------------------------------------- /subaccounts/get-balance-transfers.php: -------------------------------------------------------------------------------- 1 | START_DATE 10 | ]); 11 | 12 | $balanceTransfers = $client->subaccount()->getBalanceTransfers(VONAGE_API_KEY, $startDateFilter); -------------------------------------------------------------------------------- /subaccounts/get-credit-transfers.php: -------------------------------------------------------------------------------- 1 | START_DATE 10 | ]); 11 | 12 | $creditTransfers = $client->subaccount()->getCreditTransfers(VONAGE_API_KEY, $startDateFilter); -------------------------------------------------------------------------------- /subaccounts/get-subaccount.php: -------------------------------------------------------------------------------- 1 | subaccount()->getSubaccount(VONAGE_API_KEY, SUBACCOUNT_KEY); -------------------------------------------------------------------------------- /subaccounts/get-subaccounts.php: -------------------------------------------------------------------------------- 1 | subaccount()->getSubaccounts(VONAGE_API_KEY); -------------------------------------------------------------------------------- /subaccounts/reactivate-subaccount.php: -------------------------------------------------------------------------------- 1 | 2 | setSuspended(false); 12 | 13 | $subaccount = $client->subaccount()->updateSubaccount(VONAGE_API_KEY, SUBACCOUNT_KEY, $account); -------------------------------------------------------------------------------- /subaccounts/suspend-subaccount.php: -------------------------------------------------------------------------------- 1 | 2 | setSuspended(true); 12 | 13 | $subaccount = $client->subaccount()->updateSubaccount(VONAGE_API_KEY, SUBACCOUNT_KEY, $account); -------------------------------------------------------------------------------- /subaccounts/transfer-balance.php: -------------------------------------------------------------------------------- 1 | 2 | setFrom(VONAGE_API_KEY) 13 | ->setTo(SUBACCOUNT_KEY) 14 | ->setAmount(250); 15 | 16 | $subaccount = $client->subaccount()->makeBalanceTransfer($transferRequest); -------------------------------------------------------------------------------- /subaccounts/transfer-credit.php: -------------------------------------------------------------------------------- 1 | setFrom(VONAGE_API_KEY) 12 | ->setTo(SUBACCOUNT_KEY) 13 | ->setAmount(250); 14 | 15 | $subaccount = $client->subaccount()->makeBalanceTransfer($transferRequest); -------------------------------------------------------------------------------- /verify/cancel.php: -------------------------------------------------------------------------------- 1 | verify()->cancel(REQUEST_ID); 19 | var_dump($result->getResponseData()); 20 | } 21 | 22 | catch(Exception $e) { 23 | echo 'Message: ' .$e->getMessage(); 24 | } 25 | -------------------------------------------------------------------------------- /verify/request.php: -------------------------------------------------------------------------------- 1 | setCodeLength(4); 13 | 14 | // set locale 15 | $request->setCountry('de'); 16 | 17 | $response = $client->verify()->start($request); 18 | 19 | echo "Started verification, `request_id` is " . $response->getRequestId(); -------------------------------------------------------------------------------- /verify/request_with_workflow.php: -------------------------------------------------------------------------------- 1 | [-b ] [-w ] 14 | 15 | NUMBER the telephone number to send the Verify request to 16 | BRAND_NAME is the name of the company sending the request. Defaults to 'Acme, Inc.' 17 | WORKFLOW_ID is the workflow ID to use. Must be between 1-5 18 | 19 | Options can also be passed as environment variables. 20 | 21 | ENDHELP; 22 | 23 | if (array_key_exists('h', $options)) { 24 | echo $helpText; 25 | exit(1); 26 | } 27 | 28 | if (!defined('NUMBER')) { 29 | define('NUMBER', (array_key_exists('n', $options)) ? $options['n'] : null); 30 | } 31 | 32 | if (!defined('VERIFY_BRAND_NAME')) { 33 | define('VERIFY_BRAND_NAME', (array_key_exists('b', $options)) ? $options['b'] : 'Acme, Inc'); 34 | } 35 | 36 | if (!defined('WORKFLOW_ID')) { 37 | define('WORKFLOW_ID', (array_key_exists('w', $options)) ? $options['w'] : 4); 38 | } 39 | 40 | if (is_null(NUMBER)) { 41 | echo "Please supply a NUMBER to send a verification request to." 42 | . PHP_EOL 43 | . PHP_EOL 44 | . $helpText 45 | ; 46 | exit(1); 47 | } 48 | 49 | $request = new \Vonage\Verify\Request(NUMBER, BRAND_NAME, (int) WORKFLOW_ID); 50 | $response = $client->verify()->start($request); 51 | 52 | echo "Started verification, `request_id` is " . $response->getRequestId(); 53 | -------------------------------------------------------------------------------- /verify/search.php: -------------------------------------------------------------------------------- 1 | 14 | 15 | REQUEST_ID is the ID of a verification event 16 | 17 | ENDHELP; 18 | 19 | if (array_key_exists('h', $options)) { 20 | echo $helpText; 21 | exit(1); 22 | } 23 | 24 | if (!defined('REQUEST_ID')) { 25 | define('REQUEST_ID', (array_key_exists(1, $argv)) ? $argv[1] : null); 26 | } 27 | 28 | if (is_null(REQUEST_ID)) { 29 | echo "Please supply a REQUEST_ID to search for." 30 | . PHP_EOL 31 | . PHP_EOL 32 | . $helpText 33 | ; 34 | exit(1); 35 | } 36 | 37 | try { 38 | $result = $client->verify()->search(REQUEST_ID); 39 | echo "Request has a status of " . $result->getStatus() . PHP_EOL; 40 | } catch (\Vonage\Client\Exception\Request $e) { 41 | error_log("Client error: " . $e->getMessage()); 42 | exit(1); 43 | } catch (\Vonage\Client\Exception\Server $e) { 44 | error_log("Server error: " . $e->getMessage()); 45 | exit(1); 46 | } 47 | -------------------------------------------------------------------------------- /verify/send_psd2_request.php: -------------------------------------------------------------------------------- 1 | verify()->requestPSD2($request); 11 | 12 | echo "Started verification, `request_id` is " . $response['request_id']; 13 | -------------------------------------------------------------------------------- /verify/send_psd2_request_with_workflow.php: -------------------------------------------------------------------------------- 1 | [-b ] [-w ] 14 | 15 | NUMBER the telephone number to send the Verify request to 16 | BRAND_NAME is the name of the company sending the request. Defaults to 'Acme, Inc.' 17 | WORKFLOW_ID is the workflow ID to use. Must be between 1-5 18 | 19 | Options can also be passed as environment variables. 20 | 21 | ENDHELP; 22 | 23 | if (array_key_exists('h', $options)) { 24 | echo $helpText; 25 | exit(1); 26 | } 27 | 28 | if (!defined('RECIPIENT_NUMBER')) { 29 | define('RECIPIENT_NUMBER', (array_key_exists('n', $options)) ? $options['n'] : null); 30 | } 31 | 32 | if (!defined('PAYEE_NAME')) { 33 | define('PAYEE_NAME', (array_key_exists('b', $options)) ? $options['b'] : 'Acme, Inc'); 34 | } 35 | 36 | if (!defined('AMOUNT')) { 37 | define('AMOUNT', (array_key_exists('a', $options)) ? $options['a'] : '$10.00'); 38 | } 39 | 40 | if (!defined('WORKFLOW_ID')) { 41 | define('WORKFLOW_ID', (array_key_exists('w', $options)) ? $options['w'] : 4); 42 | } 43 | 44 | if (is_null(RECIPIENT_NUMBER)) { 45 | echo "Please supply a NUMBER to send a verification request to." 46 | . PHP_EOL 47 | . PHP_EOL 48 | . $helpText; 49 | exit(1); 50 | } 51 | 52 | $request = new \Vonage\Verify\RequestPSD2(RECIPIENT_NUMBER, BRAND_NAME, AMOUNT, (int) WORKFLOW_ID); 53 | $response = $client->verify()->requestPSD2($request); 54 | 55 | echo "Started verification, `request_id` is " . $response['request_id']; 56 | -------------------------------------------------------------------------------- /verify/trigger_next_event.php: -------------------------------------------------------------------------------- 1 | verify()->trigger(REQUEST_ID); 14 | 15 | var_dump($result->getResponseData()); -------------------------------------------------------------------------------- /verify/verify.php: -------------------------------------------------------------------------------- 1 | verify()->check(REQUEST_ID, CODE); 20 | 21 | var_dump($result->getResponseData()); -------------------------------------------------------------------------------- /verify2/cancel-request.php: -------------------------------------------------------------------------------- 1 | verify2()->cancelRequest(REQUEST_ID); 13 | -------------------------------------------------------------------------------- /verify2/check-verification-code.php: -------------------------------------------------------------------------------- 1 | verify2()->check(REQUEST_ID, CODE); 12 | } catch (\Exception $e) { 13 | var_dump($e->getMessage()); 14 | } 15 | -------------------------------------------------------------------------------- /verify2/create-template-fragment.php: -------------------------------------------------------------------------------- 1 | verify2()->createCustomTemplateFragment(TEMPLATE_ID, $createFragmentRequest); 17 | -------------------------------------------------------------------------------- /verify2/create-template.php: -------------------------------------------------------------------------------- 1 | verify2()->createCustomTemplate('my-custom-template'); -------------------------------------------------------------------------------- /verify2/delete-fragment.php: -------------------------------------------------------------------------------- 1 | verify2()->deleteCustomTemplateFragment(TEMPLATE_ID, TEMPLATE_FRAGMENT_ID); 11 | -------------------------------------------------------------------------------- /verify2/delete-template.php: -------------------------------------------------------------------------------- 1 | verify2()->deleteCustomTemplate(TEMPLATE_ID); 11 | -------------------------------------------------------------------------------- /verify2/get-fragment.php: -------------------------------------------------------------------------------- 1 | verify2()->getCustomTemplateFragment(TEMPLATE_ID, TEMPLATE_FRAGMENT_ID); 11 | -------------------------------------------------------------------------------- /verify2/get-template.php: -------------------------------------------------------------------------------- 1 | verify2()->getCustomTemplate(TEMPLATE_ID); 11 | -------------------------------------------------------------------------------- /verify2/list-fragments.php: -------------------------------------------------------------------------------- 1 | verify2()->listTemplateFragments(TEMPLATE_ID); 11 | -------------------------------------------------------------------------------- /verify2/list-templates.php: -------------------------------------------------------------------------------- 1 | verify2()->listCustomTemplates(TEMPLATE_ID); 11 | -------------------------------------------------------------------------------- /verify2/send-request-email.php: -------------------------------------------------------------------------------- 1 | verify2()->startVerification($newRequest); 12 | -------------------------------------------------------------------------------- /verify2/send-request-silent-auth.php: -------------------------------------------------------------------------------- 1 | verify2()->startVerification($newRequest); 12 | -------------------------------------------------------------------------------- /verify2/send-request-sms.php: -------------------------------------------------------------------------------- 1 | verify2()->startVerification($newRequest); 12 | -------------------------------------------------------------------------------- /verify2/send-request-voice.php: -------------------------------------------------------------------------------- 1 | verify2()->startVerification($newRequest); 12 | -------------------------------------------------------------------------------- /verify2/send-request-whatsapp-interactive.php: -------------------------------------------------------------------------------- 1 | verify2()->startVerification($newRequest); 12 | -------------------------------------------------------------------------------- /verify2/send-request-whatsapp.php: -------------------------------------------------------------------------------- 1 | verify2()->startVerification($newRequest); 12 | -------------------------------------------------------------------------------- /verify2/send-request-with-fallback.php: -------------------------------------------------------------------------------- 1 | addWorkflow($emailWorkflow); 13 | $client->verify2()->startVerification($newRequest); 14 | -------------------------------------------------------------------------------- /verify2/update-template-fragment.php: -------------------------------------------------------------------------------- 1 | verify2()->updateCustomTemplateFragment( 11 | TEMPLATE_ID, 12 | TEMPLATE_FRAGMENT_ID, 13 | 'The authentication code for your ${brand} is: ${code}' 14 | ); 15 | -------------------------------------------------------------------------------- /verify2/update-template.php: -------------------------------------------------------------------------------- 1 | verify2()->updateCustomTemplate(TEMPLATE_ID, $updateRequest); 13 | -------------------------------------------------------------------------------- /voice/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Nexmo Voice APIs with PHP 2 | 3 | ## Set up the ENV with Your Nexmo API Keys 4 | 5 | To use this sample you will first need a [Nexmo account](https://dashboard.nexmo.com/sign-up). Once you have your own API credentials, rename 6 | the `.env-example` file to `.env` and set the values as required. 7 | 8 | You also need to [buy a number](https://dashboard.nexmo.com/buy-numbers) where you can send and receive SMS messages. 9 | 10 | ## Run the Examples 11 | 12 | To run Voice APIs, you need to set up your secure Nexmo Application first. You can use [Nexmo CLI tool](https://github.com/Nexmo/nexmo-cli) to create and manage your Nexmo Applications. 13 | 14 | For more information, read the [tutorials](https://developer.nexmo.com/voice/voice-api/tutorials). 15 | -------------------------------------------------------------------------------- /voice/conference-call-slim/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "vonage/client": "^2.3", 4 | "slim/slim": "^3.8", 5 | "vlucas/phpdotenv": "^4.0" 6 | }, 7 | "scripts":{ 8 | "serve": "php -S 0.0.0.0:3000 index.php" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /voice/conference-call-slim/index.php: -------------------------------------------------------------------------------- 1 | get('/webhooks/answer', function (Request $request, Response $response) { 12 | $talk = new \Vonage\Voice\NCCO\Action\Talk('Hi, welcome to this Nexmo conference call'); 13 | $convo = new \Vonage\Voice\NCCO\Action\Conversation('nexmo-conference-standard'); 14 | 15 | $ncco = new \Vonage\Voice\NCCO\NCCO(); 16 | $ncco->addAction($talk); 17 | $ncco->addAction($convo); 18 | 19 | return new JsonResponse($ncco->toArray()); 20 | }); 21 | 22 | $app->run(); 23 | -------------------------------------------------------------------------------- /voice/conference-call.php: -------------------------------------------------------------------------------- 1 | addAction( 11 | new \Vonage\Voice\NCCO\Action\Talk('Welcome to the amazing Nexmo conference call') 12 | ) 13 | ->addAction( 14 | new \Vonage\Voice\NCCO\Action\Conversation('amazing-conference-call') 15 | ) 16 | ; 17 | 18 | header('Content-Type: application/json'); 19 | $json = json_encode($ncco); 20 | echo($json); 21 | -------------------------------------------------------------------------------- /voice/connect-a-call.php: -------------------------------------------------------------------------------- 1 | addAction( 12 | new \Vonage\Voice\NCCO\Action\Connect( 13 | new \Vonage\Voice\Endpoint\Phone(VONAGE_TO_NUMBER) 14 | ) 15 | ); 16 | 17 | header('Content-Type: application/json'); 18 | $json = json_encode($ncco); 19 | echo($json); 20 | -------------------------------------------------------------------------------- /voice/connect-call-slim/.env.dist: -------------------------------------------------------------------------------- 1 | YOUR_SECOND_NUMBER= 2 | VONAGE_NUMBER= -------------------------------------------------------------------------------- /voice/connect-call-slim/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "vonage/client": "^2.3", 4 | "slim/slim": "^3.8", 5 | "vlucas/phpdotenv": "^4.0" 6 | }, 7 | "scripts":{ 8 | "serve": "php -S 0.0.0.0:3000 index.php" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /voice/connect-call-slim/index.php: -------------------------------------------------------------------------------- 1 | load(); 12 | 13 | define('YOUR_SECOND_NUMBER', getenv('YOUR_SECOND_NUMBER')); 14 | define('VONAGE_NUMBER', getenv('VONAGE_NUMBER')); 15 | 16 | $app = new \Slim\App(); 17 | 18 | $app->get('/webhooks/answer', function (Request $request, Response $response) { 19 | $numberToConnect = new \Vonage\Voice\Endpoint\Phone(YOUR_SECOND_NUMBER); 20 | 21 | $action = new \Vonage\Voice\NCCO\Action\Connect($numberToConnect); 22 | $action->setFrom(VONAGE_NUMBER); 23 | 24 | $ncco = new \Vonage\Voice\NCCO\NCCO(); 25 | $ncco->addAction($action); 26 | 27 | return new JsonResponse($ncco->toArray()); 28 | }); 29 | 30 | $app->run(); 31 | -------------------------------------------------------------------------------- /voice/download-a-recording/index.php: -------------------------------------------------------------------------------- 1 | voice()->getRecording($recordingUrl); 10 | file_put_contents(VONAGE_RECORDING_ID .'.mp3', $data->getContents()); 11 | -------------------------------------------------------------------------------- /voice/earmuff-a-call/index.php: -------------------------------------------------------------------------------- 1 | voice()->earmuffCall(UUID); 9 | sleep(3); 10 | $client->voice()->unearmuffCall(UUID); 11 | -------------------------------------------------------------------------------- /voice/handle-user-input-with-asr-slim/README.md: -------------------------------------------------------------------------------- 1 | ### Usage 2 | 3 | This quick demo shows how the ASR NCCO events work. 4 | 5 | To run this demo: 6 | 7 | 1. Run `composer install` 8 | 2. Start the web server `composer run --timeout=0 serve` 9 | 3. Start ngrok with `ngrok http 3000`. ngrok will give you a forwarding address you can now use for your delivery receipts. 10 | 4. Copy this URL and go to your [customer dashboard](https://dashboard.nexmo.com/sign-in) 11 | 5. Go to ["Your Applications"](https://dashboard.nexmo.com/applications) 12 | 6. Click the three dots for your application and click "Edit" 13 | 7. Under "Capabilities", change the Voice "Answer URL" option to `https://[your-ngrok-url]/webhooks/answer` 14 | 7. Click "Save changes" 15 | 16 | You can now call one of the numbers linked to your application. You should be able to speak at the prompt, and 17 | have the system read back what you said. 18 | -------------------------------------------------------------------------------- /voice/handle-user-input-with-asr-slim/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "slim/slim": "^3.8", 4 | "vonage/client": "^2.3" 5 | }, 6 | "require-dev": { 7 | "squizlabs/php_codesniffer": "^3.1" 8 | }, 9 | "scripts":{ 10 | "serve": "php -S 0.0.0.0:3000 index.php" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /voice/handle-user-input-with-asr-slim/index.php: -------------------------------------------------------------------------------- 1 | get('/webhooks/answer', function (Request $request, Response $response) { 17 | $uri = $request->getUri(); 18 | $url = $uri->getScheme().'://'.$uri->getHost().':'.$uri->getPort().'/webhooks/asr'; 19 | 20 | $inputAction = new Input(); 21 | $inputAction 22 | ->setSpeechEndOnSilence(true) 23 | ->setSpeechLanguage('en-US') 24 | ->setEventWebhook(new Webhook($url)) 25 | ; 26 | $ncco = new NCCO(); 27 | $ncco 28 | ->addAction(new Talk('Please say something')) 29 | ->addAction($inputAction) 30 | ; 31 | 32 | return $response->withJson($ncco->toArray()); 33 | }); 34 | 35 | $app->map(['GET', 'POST'], '/webhooks/asr', function (Request $request, Response $response) { 36 | /** @var InputWebhook $input */ 37 | $input = Factory::createFromRequest($request); 38 | 39 | $ncco = new NCCO(); 40 | $ncco->addAction(new Talk('You said ' . $input->getSpeech()['results'][0]['text'])); 41 | 42 | return $response->withJson($ncco->toArray()); 43 | }); 44 | 45 | $app->run(); 46 | -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/app/Console/Commands/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vonage/vonage-php-code-snippets/c996d762bf140dc85207786c55db4a1078447db7/voice/inbound-calls-lumen/app/Console/Commands/.gitkeep -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | make( 32 | 'Illuminate\Contracts\Console\Kernel' 33 | ); 34 | 35 | exit($kernel->handle(new ArgvInput, new ConsoleOutput)); 36 | -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/bootstrap/app.php: -------------------------------------------------------------------------------- 1 | load(); 7 | } catch (Dotenv\Exception\InvalidPathException $e) { 8 | // 9 | } 10 | 11 | /* 12 | |-------------------------------------------------------------------------- 13 | | Create The Application 14 | |-------------------------------------------------------------------------- 15 | | 16 | | Here we will load the environment and create the application instance 17 | | that serves as the central piece of this framework. We'll use this 18 | | application as an "IoC" container and router for this framework. 19 | | 20 | */ 21 | 22 | $app = new Laravel\Lumen\Application( 23 | realpath(__DIR__.'/../') 24 | ); 25 | 26 | // $app->withFacades(); 27 | 28 | // $app->withEloquent(); 29 | 30 | /* 31 | |-------------------------------------------------------------------------- 32 | | Register Container Bindings 33 | |-------------------------------------------------------------------------- 34 | | 35 | | Now we will register a few bindings in the service container. We will 36 | | register the exception handler and the console kernel. You may add 37 | | your own bindings here if you like or you can make another file. 38 | | 39 | */ 40 | 41 | $app->singleton( 42 | Illuminate\Contracts\Debug\ExceptionHandler::class, 43 | App\Exceptions\Handler::class 44 | ); 45 | 46 | $app->singleton( 47 | Illuminate\Contracts\Console\Kernel::class, 48 | App\Console\Kernel::class 49 | ); 50 | 51 | /* 52 | |-------------------------------------------------------------------------- 53 | | Register Middleware 54 | |-------------------------------------------------------------------------- 55 | | 56 | | Next, we will register the middleware with the application. These can 57 | | be global middleware that run before and after each request into a 58 | | route or middleware that'll be assigned to some specific routes. 59 | | 60 | */ 61 | 62 | // $app->middleware([ 63 | // App\Http\Middleware\ExampleMiddleware::class 64 | // ]); 65 | 66 | // $app->routeMiddleware([ 67 | // 'auth' => App\Http\Middleware\Authenticate::class, 68 | // ]); 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Register Service Providers 73 | |-------------------------------------------------------------------------- 74 | | 75 | | Here we will register all of the application's service providers which 76 | | are used to bind services into the container. Service providers are 77 | | totally optional, so you are not required to uncomment this line. 78 | | 79 | */ 80 | 81 | // $app->register(App\Providers\AppServiceProvider::class); 82 | // $app->register(App\Providers\AuthServiceProvider::class); 83 | // $app->register(App\Providers\EventServiceProvider::class); 84 | 85 | /* 86 | |-------------------------------------------------------------------------- 87 | | Load The Application Routes 88 | |-------------------------------------------------------------------------- 89 | | 90 | | Next we will include the routes file so that they can all be added to 91 | | the application. This will provide all of the URLs the application 92 | | can respond to, as well as the controllers that may handle them. 93 | | 94 | */ 95 | 96 | $app->router->group([ 97 | 'namespace' => 'App\Http\Controllers', 98 | ], function ($router) { 99 | require __DIR__.'/../routes/web.php'; 100 | }); 101 | 102 | return $app; 103 | -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel/lumen", 3 | "description": "The Laravel Lumen Framework.", 4 | "keywords": ["framework", "laravel", "lumen"], 5 | "license": "MIT", 6 | "type": "project", 7 | "require": { 8 | "php": ">=5.6.4", 9 | "laravel/lumen-framework": "5.5.*", 10 | "vlucas/phpdotenv": "~2.2" 11 | }, 12 | "require-dev": { 13 | "fzaninotto/faker": "~1.4", 14 | "phpunit/phpunit": "~6.0", 15 | "mockery/mockery": "~0.9" 16 | }, 17 | "autoload": { 18 | "psr-4": { 19 | "App\\": "app/" 20 | } 21 | }, 22 | "autoload-dev": { 23 | "classmap": [ 24 | "tests/", 25 | "database/" 26 | ] 27 | }, 28 | "scripts": { 29 | "post-root-package-install": [ 30 | "php -r \"copy('.env.example', '.env');\"" 31 | ] 32 | }, 33 | "minimum-stability": "dev", 34 | "prefer-stable": true, 35 | "optimize-autoloader": true 36 | } 37 | -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/database/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vonage/vonage-php-code-snippets/c996d762bf140dc85207786c55db4a1078447db7/voice/inbound-calls-lumen/database/.gitkeep -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./tests 15 | 16 | 17 | 18 | 19 | ./app 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Redirect Trailing Slashes If Not A Folder... 9 | RewriteCond %{REQUEST_FILENAME} !-d 10 | RewriteRule ^(.*)/$ /$1 [L,R=301] 11 | 12 | # Handle Front Controller... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_FILENAME} !-f 15 | RewriteRule ^ index.php [L] 16 | 17 | # Handle Authorization Header 18 | RewriteCond %{HTTP:Authorization} . 19 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 20 | 21 | -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/public/index.php: -------------------------------------------------------------------------------- 1 | run(); 29 | -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/readme.md: -------------------------------------------------------------------------------- 1 | # Lumen PHP Framework 2 | 3 | [![Build Status](https://travis-ci.org/laravel/lumen-framework.svg)](https://travis-ci.org/laravel/lumen-framework) 4 | [![Total Downloads](https://poser.pugx.org/laravel/lumen-framework/d/total.svg)](https://packagist.org/packages/laravel/lumen-framework) 5 | [![Latest Stable Version](https://poser.pugx.org/laravel/lumen-framework/v/stable.svg)](https://packagist.org/packages/laravel/lumen-framework) 6 | [![Latest Unstable Version](https://poser.pugx.org/laravel/lumen-framework/v/unstable.svg)](https://packagist.org/packages/laravel/lumen-framework) 7 | [![License](https://poser.pugx.org/laravel/lumen-framework/license.svg)](https://packagist.org/packages/laravel/lumen-framework) 8 | 9 | Laravel Lumen is a stunningly fast PHP micro-framework for building web applications with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Lumen attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as routing, database abstraction, queueing, and caching. 10 | 11 | ## Official Documentation 12 | 13 | Documentation for the framework can be found on the [Lumen website](http://lumen.laravel.com/docs). 14 | 15 | ## Security Vulnerabilities 16 | 17 | If you discover a security vulnerability within Lumen, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed. 18 | 19 | ## License 20 | 21 | The Lumen framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) 22 | -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/resources/views/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vonage/vonage-php-code-snippets/c996d762bf140dc85207786c55db4a1078447db7/voice/inbound-calls-lumen/resources/views/.gitkeep -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/routes/web.php: -------------------------------------------------------------------------------- 1 | get('/', function () use ($router) { 15 | return $router->app->version(); 16 | }); 17 | 18 | $router->get('/answer', function () { 19 | $from = app('request')->input('from'); 20 | $log = date('Y-m-d H:i:s') .' '. $from.PHP_EOL; 21 | file_put_contents(__DIR__.'/../call-log.txt', $log, FILE_APPEND | LOCK_EX); 22 | 23 | $voice = 'Russell'; 24 | 25 | // If it's a UK number, use an en-GB voice 26 | if (substr($from, 0, 2) == '44') { 27 | $voice = 'Amy'; 28 | } 29 | 30 | return response()->json([ 31 | [ 32 | 'action' => 'talk', 33 | 'voiceName' => $voice, 34 | 'text' => 'Thanks for your call. We are unable to take your call at the moment but the robot will make sure we know you called.', 35 | ] 36 | ]); 37 | }); 38 | -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/tests/ExampleTest.php: -------------------------------------------------------------------------------- 1 | get('/'); 16 | 17 | $this->assertEquals( 18 | $this->app->version(), $this->response->getContent() 19 | ); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /voice/inbound-calls-lumen/tests/TestCase.php: -------------------------------------------------------------------------------- 1 | get('/webhooks/answer', function (Request $request, Response $response) { 12 | /** @var \Vonage\Voice\Webhook\Answer $call */ 13 | $call = \Vonage\Voice\Webhook\Factory::createFromRequest($request); 14 | $fromSplitIntoCharacters = implode(" ", str_split($call->getFrom())); 15 | 16 | $ncco = new \Vonage\Voice\NCCO\NCCO(); 17 | $ncco->addAction( 18 | new \Vonage\Voice\NCCO\Action\Talk('Thank you for calling from ' . $fromSplitIntoCharacters) 19 | ); 20 | 21 | return new JsonResponse($ncco); 22 | }); 23 | 24 | $app->run(); 25 | -------------------------------------------------------------------------------- /voice/make-outbound-call-ncco/index.php: -------------------------------------------------------------------------------- 1 | addAction(new \Vonage\Voice\NCCO\Action\Talk('This is a text to speech call from Nexmo')); 20 | $outboundCall->setNCCO($ncco); 21 | 22 | $response = $client->voice()->createOutboundCall($outboundCall); 23 | 24 | var_dump($response); 25 | -------------------------------------------------------------------------------- /voice/mute-a-call/index.php: -------------------------------------------------------------------------------- 1 | voice()->muteCall(UUID); 9 | sleep(3); 10 | $client->voice()->unmuteCall(UUID); 11 | -------------------------------------------------------------------------------- /voice/play-audio-stream-in-to-call/index.php: -------------------------------------------------------------------------------- 1 | voice()->streamAudio(UUID, 'https://nexmo-community.github.io/ncco-examples/assets/voice_api_audio_streaming.mp3'); 9 | -------------------------------------------------------------------------------- /voice/play-dtmf-in-to-call/index.php: -------------------------------------------------------------------------------- 1 | voice()->playDTMF(UUID, '2468#'); 9 | -------------------------------------------------------------------------------- /voice/play-tts-in-to-call/index.php: -------------------------------------------------------------------------------- 1 | setLanguage('en-US'); 9 | 10 | $client->voice()->playTTS( 11 | UUID, 12 | $action 13 | ); 14 | -------------------------------------------------------------------------------- /voice/record-a-call-split-audio/.env.dist: -------------------------------------------------------------------------------- 1 | TO_NUMBER= 2 | VONAGE_NUMBER= -------------------------------------------------------------------------------- /voice/record-a-call-split-audio/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "vonage/client": "^2.3", 4 | "slim/slim": "^3.8", 5 | "vlucas/phpdotenv": "^4.0" 6 | }, 7 | "scripts":{ 8 | "serve": "php -S 0.0.0.0:3000 index.php" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /voice/record-a-call-split-audio/index.php: -------------------------------------------------------------------------------- 1 | load(); 11 | 12 | define('TO_NUMBER', getenv('TO_NUMBER')); 13 | define('VONAGE_NUMBER', getenv('VONAGE_NUMBER')); 14 | 15 | $app = new \Slim\App(); 16 | 17 | $app->get('/webhooks/answer', function (Request $request, Response $response) { 18 | //Get our public URL for this route 19 | $uri = $request->getUri(); 20 | $url = $uri->getScheme() . '://'.$uri->getHost() . ($uri->getPort() ? ':'.$uri->getPort() : '') . '/webhooks/recording'; 21 | 22 | $record = new \Vonage\Voice\NCCO\Action\Record(); 23 | $record->setEventWebhook(new \Vonage\Voice\Webhook($url)); 24 | $record->setChannels(2); 25 | 26 | $connect = new \Vonage\Voice\NCCO\Action\Connect(new \Vonage\Voice\Endpoint\Phone(TO_NUMBER)); 27 | $connect->setFrom(VONAGE_NUMBER); 28 | 29 | $ncco = new \Vonage\Voice\NCCO\NCCO(); 30 | $ncco->addAction($connect); 31 | $ncco->addAction($record); 32 | 33 | return new JsonResponse($ncco); 34 | }); 35 | 36 | $app->post('/webhooks/recording', function (Request $request, Response $response) { 37 | /** @var \Vonage\Voice\Webhook\Record */ 38 | $recording = \Vonage\Voice\Webhook\Factory::createFromRequest($request); 39 | error_log($recording->getRecordingUrl()); 40 | 41 | return $response->withStatus(204); 42 | }); 43 | 44 | $app->run(); 45 | -------------------------------------------------------------------------------- /voice/record-a-call/.env.dist: -------------------------------------------------------------------------------- 1 | TO_NUMBER= 2 | VONAGE_NUMBER= -------------------------------------------------------------------------------- /voice/record-a-call/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "vonage/client": "^2.3", 4 | "slim/slim": "^3.8", 5 | "vlucas/phpdotenv": "^4.0" 6 | }, 7 | "scripts":{ 8 | "serve": "php -S 0.0.0.0:3000 index.php" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /voice/record-a-call/index.php: -------------------------------------------------------------------------------- 1 | load(); 11 | 12 | define('TO_NUMBER', getenv('TO_NUMBER')); 13 | define('VONAGE_NUMBER', getenv('VONAGE_NUMBER')); 14 | 15 | $app = new \Slim\App(); 16 | 17 | $app->get('/webhooks/answer', function (Request $request, Response $response) { 18 | //Get our public URL for this route 19 | $uri = $request->getUri(); 20 | $url = $uri->getScheme() . '://'.$uri->getHost() . ($uri->getPort() ? ':'.$uri->getPort() : '') . '/webhooks/recording'; 21 | 22 | $record = new \Vonage\Voice\NCCO\Action\Record(); 23 | $record->setEventWebhook(new \Vonage\Voice\Webhook($url)); 24 | 25 | $connect = new \Vonage\Voice\NCCO\Action\Connect(new \Vonage\Voice\Endpoint\Phone(TO_NUMBER)); 26 | $connect->setFrom(VONAGE_NUMBER); 27 | 28 | $ncco = new \Vonage\Voice\NCCO\NCCO(); 29 | $ncco->addAction($connect); 30 | $ncco->addAction($record); 31 | 32 | return new JsonResponse($ncco); 33 | }); 34 | 35 | $app->post('/webhooks/recording', function (Request $request, Response $response) { 36 | /** @var \Vonage\Voice\Webhook\Record */ 37 | $recording = \Vonage\Voice\Webhook\Factory::createFromRequest($request); 38 | error_log($recording->getRecordingUrl()); 39 | 40 | return $response->withStatus(204); 41 | }); 42 | 43 | $app->run(); 44 | -------------------------------------------------------------------------------- /voice/record-a-conversation/.env.dist: -------------------------------------------------------------------------------- 1 | CONF_NAME= -------------------------------------------------------------------------------- /voice/record-a-conversation/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "vonage/client": "^2.3", 4 | "slim/slim": "^3.8", 5 | "vlucas/phpdotenv": "^4.0" 6 | }, 7 | "scripts":{ 8 | "serve": "php -S 0.0.0.0:3000 index.php" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /voice/record-a-conversation/index.php: -------------------------------------------------------------------------------- 1 | load(); 11 | 12 | define('CONF_NAME', getenv('CONF_NAME')); 13 | 14 | $app = new \Slim\App(); 15 | 16 | $app->map(['GET', 'POST'], '/webhooks/event', function($request, $response) { 17 | error_log(print_r($_REQUEST, true)); 18 | }); 19 | 20 | $app->get('/webhooks/answer', function (Request $request, Response $response) { 21 | //Get our public URL for this route 22 | $uri = $request->getUri(); 23 | $url = $uri->getScheme() . '://'.$uri->getHost() . ($uri->getPort() ? ':'.$uri->getPort() : '') . '/webhooks/recordings'; 24 | 25 | $conversation = new \Vonage\Voice\NCCO\Action\Conversation(CONF_NAME); 26 | $conversation->setRecord(true); 27 | $conversation->setEventWebhook(new \Vonage\Voice\Webhook($url)); 28 | 29 | $ncco = new \Vonage\Voice\NCCO\NCCO(); 30 | $ncco->addAction($conversation); 31 | 32 | return new JsonResponse($ncco); 33 | }); 34 | 35 | $app->post('/webhooks/recordings', function (Request $request, Response $response) { 36 | /** @var \Vonage\Voice\Webhook\Record */ 37 | $recording = \Vonage\Voice\Webhook\Factory::createFromRequest($request); 38 | error_log($recording->getRecordingUrl()); 39 | 40 | return $response->withStatus(204); 41 | }); 42 | 43 | $app->run(); 44 | -------------------------------------------------------------------------------- /voice/record-a-message/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "vonage/client": "^2.0", 4 | "slim/slim": "^3.8", 5 | "vlucas/phpdotenv": "^4.0" 6 | }, 7 | "scripts":{ 8 | "serve": "php -S 0.0.0.0:3000 index.php" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /voice/record-a-message/index.php: -------------------------------------------------------------------------------- 1 | get('/webhooks/answer', function (Request $request, Response $response) { 11 | //Get our public URL for this route 12 | $uri = $request->getUri(); 13 | $url = $uri->getScheme() . '://'.$uri->getHost() . ($uri->getPort() ? ':'.$uri->getPort() : '') . '/webhooks/recording'; 14 | 15 | $record = new \Vonage\Voice\NCCO\Action\Record(); 16 | $record 17 | ->setEndOnSilence(3) 18 | ->setEndOnKey('#') 19 | ->setBeepStart(true) 20 | ->setEventWebhook(new \Vonage\Voice\Webhook($url)) 21 | ; 22 | 23 | $ncco = new \Vonage\Voice\NCCO\NCCO(); 24 | $ncco 25 | ->addAction( 26 | new \Vonage\Voice\NCCO\Action\Talk('Please leave a message after the tone, then press #. We will get back to you as soon as we can') 27 | ) 28 | ->addAction($record) 29 | ->addAction( 30 | new \Vonage\Voice\NCCO\Action\Talk('Thank you for your message. Goodbye') 31 | ) 32 | ; 33 | 34 | return new JsonResponse($ncco); 35 | }); 36 | 37 | $app->post('/webhooks/recording', function (Request $request, Response $response) { 38 | /** @var \Vonage\Voice\Webhook\Record */ 39 | $recording = \Vonage\Voice\Webhook\Factory::createFromRequest($request); 40 | error_log($recording->getRecordingUrl()); 41 | 42 | return $response->withStatus(204); 43 | }); 44 | 45 | $app->run(); 46 | -------------------------------------------------------------------------------- /voice/retrieve-call-info/index.php: -------------------------------------------------------------------------------- 1 | voice()->get(VONAGE_CALL_UUID); 9 | echo json_encode($call->toArray()); 10 | -------------------------------------------------------------------------------- /voice/retrieve-calls-info/index.php: -------------------------------------------------------------------------------- 1 | setDateStart(new DateTime('-1 Day')); 10 | $filter->setDateEnd(new DateTime()); 11 | 12 | /** @var \Vonage\Voice\Call $call */ 13 | foreach ($client->voice()->search($filter) as $call) { 14 | echo json_encode($call->toArray()) . PHP_EOL; 15 | } 16 | -------------------------------------------------------------------------------- /voice/text-to-speech-inbound.php: -------------------------------------------------------------------------------- 1 | addAction( 15 | new \Vonage\Voice\NCCO\Action\Talk("This is a call from $from and to $to. Thank you for calling.") 16 | ); 17 | 18 | header('Content-Type: application/json'); 19 | $json = json_encode($ncco); 20 | echo($json); 21 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/.env.example: -------------------------------------------------------------------------------- 1 | APP_ENV=local 2 | APP_DEBUG=true 3 | APP_KEY= 4 | APP_TIMEZONE=UTC 5 | 6 | DB_CONNECTION=mysql 7 | DB_HOST=127.0.0.1 8 | DB_PORT=3306 9 | DB_DATABASE=homestead 10 | DB_USERNAME=homestead 11 | DB_PASSWORD=secret 12 | 13 | CACHE_DRIVER=file 14 | QUEUE_DRIVER=sync 15 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | /.idea 3 | Homestead.json 4 | Homestead.yaml 5 | .env 6 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/app/Console/Commands/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vonage/vonage-php-code-snippets/c996d762bf140dc85207786c55db4a1078447db7/voice/text-to-speech-outbound-lumen/app/Console/Commands/.gitkeep -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | make( 32 | 'Illuminate\Contracts\Console\Kernel' 33 | ); 34 | 35 | exit($kernel->handle(new ArgvInput, new ConsoleOutput)); 36 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/bootstrap/app.php: -------------------------------------------------------------------------------- 1 | load(); 7 | } catch (Dotenv\Exception\InvalidPathException $e) { 8 | // 9 | } 10 | 11 | /* 12 | |-------------------------------------------------------------------------- 13 | | Create The Application 14 | |-------------------------------------------------------------------------- 15 | | 16 | | Here we will load the environment and create the application instance 17 | | that serves as the central piece of this framework. We'll use this 18 | | application as an "IoC" container and router for this framework. 19 | | 20 | */ 21 | 22 | $app = new Laravel\Lumen\Application( 23 | realpath(__DIR__.'/../') 24 | ); 25 | 26 | // $app->withFacades(); 27 | 28 | // $app->withEloquent(); 29 | 30 | /* 31 | |-------------------------------------------------------------------------- 32 | | Register Container Bindings 33 | |-------------------------------------------------------------------------- 34 | | 35 | | Now we will register a few bindings in the service container. We will 36 | | register the exception handler and the console kernel. You may add 37 | | your own bindings here if you like or you can make another file. 38 | | 39 | */ 40 | 41 | $app->singleton( 42 | Illuminate\Contracts\Debug\ExceptionHandler::class, 43 | App\Exceptions\Handler::class 44 | ); 45 | 46 | $app->singleton( 47 | Illuminate\Contracts\Console\Kernel::class, 48 | App\Console\Kernel::class 49 | ); 50 | 51 | /* 52 | |-------------------------------------------------------------------------- 53 | | Register Middleware 54 | |-------------------------------------------------------------------------- 55 | | 56 | | Next, we will register the middleware with the application. These can 57 | | be global middleware that run before and after each request into a 58 | | route or middleware that'll be assigned to some specific routes. 59 | | 60 | */ 61 | 62 | // $app->middleware([ 63 | // App\Http\Middleware\ExampleMiddleware::class 64 | // ]); 65 | 66 | // $app->routeMiddleware([ 67 | // 'auth' => App\Http\Middleware\Authenticate::class, 68 | // ]); 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Register Service Providers 73 | |-------------------------------------------------------------------------- 74 | | 75 | | Here we will register all of the application's service providers which 76 | | are used to bind services into the container. Service providers are 77 | | totally optional, so you are not required to uncomment this line. 78 | | 79 | */ 80 | 81 | // $app->register(App\Providers\AppServiceProvider::class); 82 | // $app->register(App\Providers\AuthServiceProvider::class); 83 | // $app->register(App\Providers\EventServiceProvider::class); 84 | 85 | /* 86 | |-------------------------------------------------------------------------- 87 | | Load The Application Routes 88 | |-------------------------------------------------------------------------- 89 | | 90 | | Next we will include the routes file so that they can all be added to 91 | | the application. This will provide all of the URLs the application 92 | | can respond to, as well as the controllers that may handle them. 93 | | 94 | */ 95 | 96 | $app->router->group([ 97 | 'namespace' => 'App\Http\Controllers', 98 | ], function ($router) { 99 | require __DIR__.'/../routes/web.php'; 100 | }); 101 | 102 | return $app; 103 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel/lumen", 3 | "description": "The Laravel Lumen Framework.", 4 | "keywords": ["framework", "laravel", "lumen"], 5 | "license": "MIT", 6 | "type": "project", 7 | "require": { 8 | "php": ">=5.6.4", 9 | "laravel/lumen-framework": "5.5.*", 10 | "vlucas/phpdotenv": "~2.2", 11 | "vonage/client": "^1.1", 12 | "guzzlehttp/guzzle": "^6.3" 13 | }, 14 | "require-dev": { 15 | "fzaninotto/faker": "~1.4", 16 | "phpunit/phpunit": "~6.0", 17 | "mockery/mockery": "~0.9" 18 | }, 19 | "autoload": { 20 | "psr-4": { 21 | "App\\": "app/" 22 | } 23 | }, 24 | "autoload-dev": { 25 | "classmap": [ 26 | "tests/", 27 | "database/" 28 | ] 29 | }, 30 | "scripts": { 31 | "post-root-package-install": [ 32 | "php -r \"copy('.env.example', '.env');\"" 33 | ] 34 | }, 35 | "minimum-stability": "dev", 36 | "prefer-stable": true, 37 | "optimize-autoloader": true 38 | } 39 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/database/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vonage/vonage-php-code-snippets/c996d762bf140dc85207786c55db4a1078447db7/voice/text-to-speech-outbound-lumen/database/.gitkeep -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./tests 15 | 16 | 17 | 18 | 19 | ./app 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Redirect Trailing Slashes If Not A Folder... 9 | RewriteCond %{REQUEST_FILENAME} !-d 10 | RewriteRule ^(.*)/$ /$1 [L,R=301] 11 | 12 | # Handle Front Controller... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_FILENAME} !-f 15 | RewriteRule ^ index.php [L] 16 | 17 | # Handle Authorization Header 18 | RewriteCond %{HTTP:Authorization} . 19 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 20 | 21 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/public/index.php: -------------------------------------------------------------------------------- 1 | run(); 29 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/readme.md: -------------------------------------------------------------------------------- 1 | # Lumen PHP Framework 2 | 3 | [![Build Status](https://travis-ci.org/laravel/lumen-framework.svg)](https://travis-ci.org/laravel/lumen-framework) 4 | [![Total Downloads](https://poser.pugx.org/laravel/lumen-framework/d/total.svg)](https://packagist.org/packages/laravel/lumen-framework) 5 | [![Latest Stable Version](https://poser.pugx.org/laravel/lumen-framework/v/stable.svg)](https://packagist.org/packages/laravel/lumen-framework) 6 | [![Latest Unstable Version](https://poser.pugx.org/laravel/lumen-framework/v/unstable.svg)](https://packagist.org/packages/laravel/lumen-framework) 7 | [![License](https://poser.pugx.org/laravel/lumen-framework/license.svg)](https://packagist.org/packages/laravel/lumen-framework) 8 | 9 | Laravel Lumen is a stunningly fast PHP micro-framework for building web applications with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Lumen attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as routing, database abstraction, queueing, and caching. 10 | 11 | ## Official Documentation 12 | 13 | Documentation for the framework can be found on the [Lumen website](http://lumen.laravel.com/docs). 14 | 15 | ## Security Vulnerabilities 16 | 17 | If you discover a security vulnerability within Lumen, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed. 18 | 19 | ## License 20 | 21 | The Lumen framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) 22 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/resources/views/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vonage/vonage-php-code-snippets/c996d762bf140dc85207786c55db4a1078447db7/voice/text-to-speech-outbound-lumen/resources/views/.gitkeep -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/routes/web.php: -------------------------------------------------------------------------------- 1 | get('/', function () use ($router) { 15 | return $router->app->version(); 16 | }); 17 | 18 | $router->get('/answer', function () { 19 | 20 | $client = new GuzzleHttp\Client(); 21 | $apiResponse = json_decode($client->get('http://api.icndb.com/jokes/random?limitTo=[nerdy]')->getBody()); 22 | 23 | return response()->json([ 24 | [ 25 | 'action' => 'talk', 26 | 'voiceName' => 'Amy', 27 | 'text' => $apiResponse->value->joke 28 | ] 29 | ]); 30 | }); 31 | 32 | $router->get('/makeCall/{number}', function ($number) { 33 | $keypair = new \Vonage\Client\Credentials\Keypair( 34 | file_get_contents(__DIR__ . '/../private.key'), 35 | 'APPLICATION_ID' 36 | ); 37 | 38 | $client = new \Vonage\Client($keypair); 39 | 40 | $client->calls()->create([ 41 | 'to' => [[ 42 | 'type' => 'phone', 43 | 'number' => $number 44 | ]], 45 | 'from' => [ 46 | 'type' => 'phone', 47 | 'number' => 'YOUR_VONAGE_NUMBER' 48 | ], 49 | 'answer_url' => ['https://example.com/answer'] 50 | ]); 51 | }); 52 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/tests/ExampleTest.php: -------------------------------------------------------------------------------- 1 | get('/'); 16 | 17 | $this->assertEquals( 18 | $this->app->version(), $this->response->getContent() 19 | ); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound-lumen/tests/TestCase.php: -------------------------------------------------------------------------------- 1 | get('/webhook/answer', function (Request $request, Response $response) { 12 | $client = new GuzzleHttp\Client(); 13 | $apiResponse = json_decode($client->get('http://api.icndb.com/jokes/random?limitTo=[nerdy]')->getBody()); 14 | 15 | $ncco = [ 16 | [ 17 | 'action' => 'talk', 18 | 'voiceName' => 'Amy', 19 | 'text' => $apiResponse->value->joke 20 | ] 21 | ]; 22 | 23 | $response->getBody()->write(json_encode($ncco)); 24 | 25 | return $response 26 | ->withHeader('Content-Type', 'application/json'); 27 | }); 28 | 29 | $app->get('/makeCall/{number}', function (Request $request, Response $response, array $args) { 30 | $keypair = new \Vonage\Client\Credentials\Keypair( 31 | file_get_contents(__DIR__ . '/private.key'), 32 | 'APPLICATION_ID' 33 | ); 34 | 35 | $client = new \Vonage\Client($keypair); 36 | 37 | $client->calls()->create([ 38 | 'to' => [[ 39 | 'type' => 'phone', 40 | 'number' => $args['number'] 41 | ]], 42 | 'from' => [ 43 | 'type' => 'phone', 44 | 'number' => 'YOUR_VONAGE_NUMBER' 45 | ], 46 | 'answer_url' => ['https://www.example.com/webhook/answer'] 47 | ]); 48 | 49 | return $response 50 | ->withHeader('Content-Type', 'application/json') 51 | ->withStatus(200); 52 | }); 53 | 54 | $app->run(); 55 | -------------------------------------------------------------------------------- /voice/text-to-speech-outbound.php: -------------------------------------------------------------------------------- 1 | setAnswerWebhook( 21 | new \Vonage\Voice\Webhook( 22 | 'https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json', 23 | \Vonage\Voice\Webhook::METHOD_GET 24 | ) 25 | ); 26 | $response = $client->voice()->createOutboundCall($outboundCall); 27 | 28 | var_dump($response); 29 | -------------------------------------------------------------------------------- /voice/transfer-a-call-with-ncco/index.php: -------------------------------------------------------------------------------- 1 | voice()->get(UUID); 22 | $ncco = new \Vonage\Voice\NCCO\NCCO(); 23 | $ncco->addAction(new \Vonage\Voice\NCCO\Action\Talk('This call was transferred')); 24 | 25 | $client->voice()->transferCall( 26 | $call->getUuid(), 27 | new \Vonage\Voice\NCCO\Action\Transfer($ncco) 28 | ); 29 | } catch (\Vonage\Client\Exception\Request $e) { 30 | error_log("Client error: " . $e->getMessage()); 31 | exit(1); 32 | } catch (\Vonage\Client\Exception\Server $e) { 33 | error_log("Server error: " . $e->getMessage()); 34 | exit(1); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /voice/transfer-a-call/index.php: -------------------------------------------------------------------------------- 1 | voice()->get(UUID); 9 | $client->voice()->transferCall( 10 | $call->getUuid(), 11 | new \Vonage\Voice\NCCO\Action\Transfer("https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/transfer.json") 12 | ); 13 | -------------------------------------------------------------------------------- /voice/trigger-notify-action/README.md: -------------------------------------------------------------------------------- 1 | ### Usage 2 | 3 | This quick demo shows how the Notification NCCO events work. 4 | 5 | To run this demo: 6 | 7 | 1. Run `composer install` 8 | 2. Start the web server `composer run --timeout=0 serve` 9 | 3. Start ngrok with `ngrok http 3000`. ngrok will give you a forwarding address you can now use for your delivery receipts. 10 | 4. Copy this URL and go to your [customer dashboard](https://dashboard.nexmo.com/sign-in) 11 | 5. Go to ["Your Applications"](https://dashboard.nexmo.com/applications) 12 | 6. Click the three dots for your application and click "Edit" 13 | 7. Under "Capabilities", change the Voice "Answer URL" option to `https://your-ngrok-url//webhooks/answer` 14 | 8. Under "Capabilities", change the Voice "Event URL" option to `https://your-ngrok-url//webhooks/event` 15 | 7. Click "Save changes" 16 | 17 | You can now call one of the numbers linked to your application. You can view the console output to see the events 18 | as well as the notification event. 19 | -------------------------------------------------------------------------------- /voice/trigger-notify-action/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "vonage/client": "^2.3", 4 | "slim/slim": "^3.8", 5 | "vlucas/phpdotenv": "^4.0" 6 | }, 7 | "scripts":{ 8 | "serve": "php -S 0.0.0.0:3000 index.php" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /voice/trigger-notify-action/index.php: -------------------------------------------------------------------------------- 1 | get('/webhooks/answer', function (Request $request, Response $response) { 12 | //Get our public URL for this route 13 | $uri = $request->getUri(); 14 | $url = $uri->getScheme() . '://'.$uri->getHost() . ($uri->getPort() ? ':'.$uri->getPort() : '') . '/webhooks/notification'; 15 | 16 | $notify = new \Vonage\Voice\NCCO\Action\Notify( 17 | ['foo' => 'bar'], 18 | new \Vonage\Voice\Webhook($url, 'GET') 19 | ); 20 | 21 | $ncco = new \Vonage\Voice\NCCO\NCCO(); 22 | $ncco 23 | ->addAction( 24 | new \Vonage\Voice\NCCO\Action\Talk('Thanks for calling the notification line') 25 | ) 26 | ->addAction($notify) 27 | ->addAction( 28 | new \Vonage\Voice\NCCO\Action\Talk('You will never hear me as the notification URL will return an NCCO') 29 | ) 30 | ; 31 | 32 | return new JsonResponse($ncco); 33 | }); 34 | 35 | $app->map(['GET', 'POST'], '/webhooks/notification', function (Request $request, Response $response) { 36 | /** @var \Vonage\Voice\Webhook\Event */ 37 | $event = \Vonage\Voice\Webhook\Factory::createFromRequest($request); 38 | error_log(print_r($event, true)); 39 | 40 | $ncco = new \Vonage\Voice\NCCO\NCCO(); 41 | $ncco->addAction( 42 | new \Vonage\Voice\NCCO\Action\Talk('Your notification has been received, loud and clear') 43 | ); 44 | 45 | return new JsonResponse($ncco); 46 | }); 47 | 48 | $app->map(['GET', 'POST'], '/webhooks/event', function (Request $request, Response $response) { 49 | /** @var \Vonage\Voice\Webhook\Event */ 50 | $event = \Vonage\Voice\Webhook\Factory::createFromRequest($request); 51 | error_log(print_r($event, true)); 52 | 53 | return $response->withStatus(204); 54 | }); 55 | 56 | $app->run(); 57 | -------------------------------------------------------------------------------- /voice/user-input-dtmf-slim/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "vonage/client": "^2.3", 4 | "slim/slim": "^3.8", 5 | "vlucas/phpdotenv": "^4.0" 6 | }, 7 | "scripts":{ 8 | "serve": "php -S 0.0.0.0:3000 index.php" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /voice/user-input-dtmf-slim/index.php: -------------------------------------------------------------------------------- 1 | get('/webhooks/answer', function (Request $request, Response $response) { 11 | //Get our public URL for this route 12 | $uri = $request->getUri(); 13 | $url = $uri->getScheme() . '://'.$uri->getHost() . ($uri->getPort() ? ':'.$uri->getPort() : '') . '/webhooks/dtmf'; 14 | 15 | $input = new \Vonage\Voice\NCCO\Action\Input(); 16 | $input 17 | ->setEnableDtmf(true) 18 | ->setEventWebhook(new \Vonage\Voice\Webhook($url, 'GET')) 19 | ; 20 | 21 | $ncco = new \Vonage\Voice\NCCO\NCCO(); 22 | $ncco 23 | ->addAction( 24 | new \Vonage\Voice\NCCO\Action\Talk('Please enter a digit') 25 | ) 26 | ->addAction($input) 27 | ; 28 | 29 | return new JsonResponse($ncco); 30 | }); 31 | 32 | $app->map(['GET', 'POST'], '/webhooks/dtmf', function (Request $request, Response $response) { 33 | /** @var \Vonage\Voice\Webhook\Input $input */ 34 | $input = \Vonage\Voice\Webhook\Factory::createFromRequest($request); 35 | $ncco = new \Vonage\Voice\NCCO\NCCO(); 36 | $ncco->addAction( 37 | new \Vonage\Voice\NCCO\Action\Talk('You pressed '. $input->getDtmf()['digits']) 38 | ); 39 | 40 | return new JsonResponse($ncco); 41 | }); 42 | 43 | $app->run(); 44 | -------------------------------------------------------------------------------- /vonage_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vonage/vonage-php-code-snippets/c996d762bf140dc85207786c55db4a1078447db7/vonage_logo.png --------------------------------------------------------------------------------