Giter Club home page Giter Club logo

nexmo-php-lib's Introduction

Sending SMS via the Nexmo SMS gateway.


Quick Examples
--------------

1) Sending an SMS

    $sms = new NexmoMessage('account_key', 'account_secret');
    $sms->sendText( '+447234567890', 'MyApp', 'Hello world!' );



2) Recieving SMS 

     $sms = new NexmoMessage('account_key', 'account_secret');
     if ($sms->inboundText()) {
         $sms->reply('You said: ' . $sms->text);
     }



3) Recieving a message receipt

     $receipt = new NexmoReceipt();
     if ($receipt->exists()) {
         switch ($receipt->status) {
             case $receipt::STATUS_DELIVERED:
                 // The message was delivered to the handset!
                 break;
             
             case $receipt::STATUS_FAILED:
             case $receipt::STATUS_EXPIRED:
                 // The message failed to be delivered
                 break;
         }
     }



4) List purchased numbers on your account

     $account = new NexmoAccount('account_key', 'account_secret');
     $numbers = $account->numbersList();






Most Frequent Issues
--------------------

 Sending a message returns false.

    This is usually due to your webserver unable to send a request to
    Nexmo. Make sure the following are met:

    1) Either CURL is enabled for your PHP installation or the PHP
       option 'allow_url_fopen' is set to 1 (default).
    
    2) You have no firewalls blocking access to rest.nexmo.com/sms/json
       on port 443.



 Your message appears to have been sent but you do not recieve it.

    Run the example.php file included. This will show any errors that
    are returned from Nexmo.

nexmo-php-lib's People

Contributors

bpneal avatar frak avatar prawnsalad avatar swahome avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nexmo-php-lib's Issues

Fatal error: Class 'NexmoMessage' not found

Not sure why I'm getting this. I'm not a pro with composer, but I included this package like so:

"require" : {
"prawnsalad/nexmo": "dev-master"
}

The package gets built in my vendor folder no problem, but when I try running:

require 'vendor/autoload.php';
$sms = new NexmoMessage(NEXMO_KEY, NEXMO_SECRET);
$sms->sendText($phone, "app", "yo");

I get the error: Fatal error: Class 'NexmoMessage' not found. Any idea why this could be? I also tried explicitly use NexmoMessage, but that didn't work either. Thanks

sendRequest seems to fail

Hi, thanks for your work on this PHP lib!

I was trying to run the example with my Nexmo account.
I have of course replaced the key and the secret but I unfortunately obtain "Cannot display an overview of this response".

I tried to debug the problem.
Apparently $from_nexmo is empty while this is $to_nexmo:
Array ( [url] => https://rest.nexmo.com/sms/json [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => 0 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 )

Does this look correct?
Am I doing something wrong?

Thank you.

Expose all Nexmo flags in NexmoMessage, i.e. concat-*

https://docs.nexmo.com/index.php/sms-api/handle-inbound-message
Some of the missing:
keyword: First word in the message body, typically used with short codes
concat: Set to true if a MO concatenated message is detected
concat-ref: Transaction reference, all message parts will shared the same transaction reference
concat-total: The total number of parts in this concatenated message set
concat-part: The part number of this message within the set (starts at 1)

Or you could have an originalMessage property what would hold all get parameters so that new additions to Nexmo API can be used without updating your library.

Missing proper class contructors

I noticed these kind of constructors in the classes:

function NexmoMessage ($api_key, $api_secret) {
    $this->nx_key = $api_key;
    $this->nx_secret = $api_secret;
}

I believe these are PHP4 style constructors and if I'm not mistaken, will be deprecated. It might be good to replace them with proper constructors instead:

http://php.net/manual/en/language.oop5.decon.php

License file missing

Could you please add a license file?

Currently I'm not sure under what license your source is.

Problem to send SMS

Hello,
I installed that library in my local server.
I added api key and secret with to and from parameter in example.php
When i run example.php page in local then display OK status but message not send in phone number.
I am in india and a also add country code before phone number.
Also i used free account of nexmo.
Please guide me what is the problem?

Message length problem

Hello,

I'm currently using this lib to connect to the Nexmo API. But I'm having some issues with the length of a text message.

I have a message that contains 160 chars, but still get split up into 3 separate SMS messages. According to the Nexmo website, 160 characters should fit into 1 message.
But why doesn't Nexmo send just 1 message?

normaliseKeys() to protected

Hi?

There was some problem in using normaliseKeys() in my environment. The problem was caused by 'instanceof' function. To workaround this, I changed this to something like is_a($obj, '\stdClass') instead.

To keep the maintainability I don't want to make a modification to your code directly. It would be nice if I can override the method at child class.

Error when have bad credentials

I found an error when authentication fails on nexmo.

The function "nexmoParse" parses every messages and sums the total cost like this:
$total_cost = $total_cost + (float)$msg->messageprice;

But when you have an authentication error the parser gives an error because "messageprice" is not defined.

I corrected myself by change the code to:
if (isset($msg->messageprice)) {
$total_cost = $total_cost + (float)$msg->messageprice;
}

Add composer.json and add library to Packagist.org

Can you please add a basic composer.json and then add the library to packagist.org?

The content of the json file should be something like

{
"description": "PHP library for sending text messages via Nexmo.",
"name": "prawnsalad/nexmo-php-lib",
"type": "library",
"keywords" : ["nexmo", "php"],
"homepage": "https://github.com/prawnsalad/Nexmo-PHP-lib"
],
"require": {
"php": ">=5.3.2"
},
"autoload": {
"psr-0": {
"Nexmo": ""
}
}
}

PSR-4 Autoloading Failing

In composer.json it is specified that a PSR-4 Autoloader can be used:
https://github.com/prawnsalad/Nexmo-PHP-lib/blob/master/composer.json#L8-L10

However, the classes in the library do not have a namespace which is required by PSR-4 http://www.php-fig.org/psr/psr-4/

Either a namespace should be added to all three classes like so:

namespace PrawnSalad\Nexmo;

or the composer.json should be updated to use a classmap instead of PSR-4
https://getcomposer.org/doc/04-schema.md#classmap

Add to Packagist.org

Hi. Would you consider adding this lib to packagist.org please? That way it can be downloaded & managed via Composer.

It's just a matter of creating a composer.json file and then submitting the repo to https://packagist.org

Create a realease tag

Hello

Is that possible to create a release tag like 1.0.0 ?

Like this we can use it with composer in a clean way instead of putting dev-master.

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.