hilink-modem
A node.js wrapper around the Huawei HiLink REST API
Setup
npm install hilink-modem
Usage
const Modem = const modem = modem
API
new Modem(options)
Type: function
Returns an instance of Modem
options
Type: object
Option | Default | Type | Description |
---|---|---|---|
modemIp | 192.168.8.1 |
string |
The IP address of the modem |
messageDelay | 1 |
number |
The number of seconds to wait between looking for new messages in Modem.onMessage |
bigMessageDelay | 30 |
number |
The number of seconds to wait before looking for a new message after first receiving a multi-part SMS (The HiLink API initially returns scrambled messages after first receiving a multi-part SMS) |
sendMessageStatusDelay | 1 |
number |
The number of seconds to wait between checking status of message sent with Modem.sendMessage |
waitForPendingRequest | true |
boolean |
If a new request is started while there is a pending request to the API, the new request will not be executed until the pending request is no longer pending |
Modem.sendMessage(options)
Type: function
Returns a Promise
Send an SMS text message
modem
options
Type: object
Option | Type | Description |
---|---|---|
receiver | string |
The telephone number of the receiver |
text | string |
The text of the message |
Modem.getMessages(options)
Type: function
Returns a Promise
Get SMS text messages
modem modem modem
options
Type: object
Option | Default | Type | Allowed values | Description |
---|---|---|---|---|
type | received |
string |
received |sent |drafted |
The mailbox to get messages from |
count | 20 |
number |
1 to 20 |
The number of messages to get |
page | 1 |
number |
1 to {pageCount} |
The page to get messages from |
sort | ascending |
string |
ascending |descending |
The sort direction |
Modem.onMessage(callback)
Type: function
Start listening for incoming SMS text messages
modem
callback
Type: function
A callback function that will be called when a new message is received. Async functions are supported
Modem.apiRequest(endpoint, options)
Type: function
Returns a Promise
Make a custom request to the HiLink API, with tokens provided.
If you use this to write a method not covered by this package, feel free to make a PR!
modem
endpoint
Type: string
The endpoint to request. Will be prepended with /api
options
Type: object
Option | Default | Type | Allowed values | Description |
---|---|---|---|---|
method | GET |
string |
GET |POST |PUT |PATCH |HEAD |DELETE |
The request method |
body | undefined |
object |
The request body in JSON |
The HiLink API only accepts XML. body
will be converted to XML, see example below.
From this:
const body = Ascending: 1 BoxType: 1 PageIndex: 1 ReadCount: 20 SortType: 0 UnreadPreferred: 1
To this:
1 1 1 20 0 1
Devices
See https://github.com/zentus/hilink-modem/issues/1