Sending messages using the Wecloud message Push interface version Nodejs

Source: Internet
Author: User

Wecloud is a start-up product that is currently mostly doing Android and iOS messaging push this piece. They provide a protocol for sending messages to the device, as described in the message push protocol.

This article will use Nodejs to complete the server-side SDK that pushes messages to app users based on this push protocol.

First you need to register an account, and then the system will automatically generate a test demo for you, you can scan the QR code or download to the computer to obtain the APK file, and then install it on your phone after you can test the delivery effect, each application will have corresponding Appkey and Master Secret These two properties, which are present as credentials for sending messages, which the interface needs to recognize the sender's identity when sending the message. You can get Appkey in the app list and get Master Secret in the details.


Of course, if you have your own app and need to integrate the message push service, see the Wecloud message Client SDK documentation.


The above is an introduction to what you need to know before you write a representative, and then you can code it.

The implementation of the complete code on my github has been open source, welcome criticism and spit Groove.

I wrote the Nodejs version of the message Push SDK only need to rely on the request, the code from the Git clone down only need to perform the NPM install installed dependencies can be used.

Use the sample to see the following code:

/** * Created by Luzhen on 14-9-24. */var messageclient = require ('./messageclient ');//Introduce messageclient, which is used to implement message sending Var message_enum=require ('./ Messageenum ');//introduction of Message enumeration VAR messagetype=message_enum.messagetype;//message Type enumeration var Messageaction=message_ ENUM.MESSAGEACTION;//Message Action enumeration var sendtype=message_enum.sendtype;//message Send type enumeration var countries=message_enum.countries;// National Dimension enumeration var tags=message_enum.tags;//tag enumeration var nettypes=message_enum.nettypes;//network type enumeration var Platforms=message_ Enum.platforms;var Message=require ('./message ');//introduction of the message module VAR client =messageclient.instance (' Dxzbsf7ioc6ackozcot8r9ij ', ' zkuivpp71e51z0y6hlsho9t15ms504ac ');//Gets a Messageclient object message. Setmessagetype ( messagetype.notification). Setmessagetitle (' Test title '). Setmessagecontent (' Test content '). Setmessageaction (Mes Sageaction.open_app). Setsendtype (Sendtype.realtime). Setplatforms (platforms. ANDROID);//link Set message//Send to everyone client.sendall (Message,function (err,res) {console.log (err);//err contains error message Console.log (RES) ;//res contains the response result conSole.log (' This method is used to configure the callback method that you want to execute after the message is sent successfully '); /Send Message.settokens (' 140775224048952ddd91a4ced3b74 ') by token; Client.sendbytokens (Message,function () {Console.log (' This method is used to configure the callback method that you want to execute after the message is sent successfully '); /Send message.setcountries by dimension (countries. other); Message.settags (tags. Online_shopping,tags. Passenger)///Set multiple label message.setnettypes (NETTYPES._3G,NETTYPES.WIFI);//Set multiple network types Message.setchannels ("Google", " Baidu "), Message.setversions (" 1.0 "," 1.1 "); Client.sendbydimensions (Message,function () {Console.log (' This method is used to configure the callback method that you want to execute after the message is sent successfully;});

Currently, the SDK supports three message push modes, which are sent to all users, sent by dimension (currently supported in 5 Dimensions: Country type, network type, label, channel, and version) and sent by token (token is used to identify a specific user).

Supports message push for Android and iOS platforms (iOS includes production and development environments).

Sending messages using the Wecloud message Push interface version Nodejs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.