Giter Site home page Giter Site logo

telstra / messagingapi-sdk-node Goto Github PK

View Code? Open in Web Editor NEW
10.0 11.0 6.0 4.74 MB

Telstra Messaging SDK - Node Library

Home Page: https://dev.telstra.com

License: Apache License 2.0

JavaScript 62.85% TypeScript 37.15%
sms mms telstradev nodejs sdk telstra

messagingapi-sdk-node's People

Contributors

ananditabhatt-tdev avatar christrewin avatar dependabot[bot] avatar developersteve avatar telstradevelopers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

messagingapi-sdk-node's Issues

Issue with browersify

Hi there,

I'm using the free message API and it can successfully send the message with node.js, here is my code:
`

    var TelstraMessaging = require('Telstra_Messaging');

    var api = new TelstraMessaging.AuthenticationApi()

    var clientId = "MY CID";

    var clientSecret = "MY CS";

    var grantType = "client_credentials";

    var getToken = false;

    ////////////////////////////////////////////////////
    //Input the phone number and messagebody here
    var phone = "0411111111";

    var messagebody = "Welcome!";
    ////////////////////////////////////////////////////

    var callback = function(error, data, response) {
    if (error) {
        console.error(error);
    } else {
        console.log('Generated OAuth Token.');
        //console.log(data.access_token);
            var OToken = data.access_token;
            var defaultClient = TelstraMessaging.ApiClient.instance;

            // Configure OAuth2 access token for authorization: auth
            var auth = defaultClient.authentications['auth'];
            auth.accessToken = data.access_token;

            var apiInstance = new TelstraMessaging.ProvisioningApi();

            var body = new TelstraMessaging.ProvisionNumberRequest(); 

            var callback = function(error, data, response) {
            if (error) {
                console.error(error);
            } else {
                console.log('Created Subscription.');
                // console.log(data.destinationAddress);
                // console.log(OToken);
                var defaultClient = TelstraMessaging.ApiClient.instance;

                // Configure OAuth2 access token for authorization: auth
                var auth = defaultClient.authentications['auth'];
                auth.accessToken = OToken;

                var apiInstance = new TelstraMessaging.MessagingApi();

                var payload = {
                "to": phone,
                "body": messagebody
                }            
                // SendSMSRequest | A JSON or XML payload containing the recipient's phone number and text message.  This number can be in international format if preceeded by a ‘+’ or in national format ('04xxxxxxxx') where x is a digit.


                var callback = function(error, data, response) {
                if (error) {
                    console.error(error);
                } else {
                    console.log("Message sent.");
                }
                };
                apiInstance.sendSMS(payload, callback);
                
            }
            };
            apiInstance.createSubscription(body, callback);
            
    }
    };
    api.authToken(clientId, clientSecret, grantType, callback);

`
However, the bundle.js file which generated by browersify cannot successfully in the browser. Here is the error info reported by browser:

`

bundle.js:26 Generated OAuth Token.

2tapi.telstra.com/v2/messages/provisioning/subscriptions:1 
Failed to load resource: the server responded with a status of 401 (Unauthorized)

index.html:1 Failed to load https://tapi.telstra.com/v2/messages/provisioning/subscriptions: 
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 401.

bundle.js:41 Error: Request has been terminated
Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.
    at Request.crossDomainError (bundle.js:3643)
    at XMLHttpRequest.xhr.onreadystatechange (bundle.js:3751)
callback @ bundle.js:41

`

This report means I can get OAuth Token succesuffly but I cannot run create subscription successfully.
How can I fix it?

Cheers

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.