Unofficial Nodejs SDK for Intellipush
This SDK is actively developed and maintained by Prek AS - an official Intellipush partner.
For compatibility with Node.js versions < 12, please install the globalThis polyfill.
Add @prek-no/intellipush-sdk
dependency to your project:
npm install @prek-no/intellipush-sdk
or using Yarn
yarn add @prek-no/intellipush-sdk
This package delivers its own typings. If you have any problems with typings, add the package to the types
array in your tsconfig.json
:
{
"compilerOptions": {
"types": [
"@prek-no/intellipush-sdk"
]
}
}
Initialize the Intellipush Client by passing in the credentials:
// const globalThis = require('globalthis')(); // uncomment if NodeJS < NodeJS versions < 12
import { Intellipush } from '@prek-no/intellipush-sdk'
const intellipush = new Intellipush({
clientId: '<client_id>', // e.g process.env.INTELLIPUSH_CLIENT_ID
clientSecret: '<client_secret>', // e.g process.env.INTELLIPUSH_CLIENT_SECRET
proxyUrl: '<proxy_url>' // Optional Proxy URL
})
You can sign in using OAuth2 (Client Credentials) by calling the authenticate
method:
// Async
try {
await intellipush.authenticate()
} catch(err: any) {
console.log(err)
}
// Promise
intellipush.authenticate().then(() => {
console.log('Authenticated!')
}).catch(() => {
console.log('Authentication failed!')
})
This SDK provides you with some convenient data models. All models accepts an object in the constructor as well as some setter functions. See example below.
const contact = new ContactModel({
name: 'Tim Cook',
countrycode: '0047',
phonenumber: '12345678'
})
const result: IContactResponse = await intellipush.contact.create(contact)
console.log(result.data.name)
const contact = new ContactModel()
contact.setName('Tim cook')
.setCountrycode('0047')
.setPhonenumber('12345678')
.setEmail('tim@example.com')
const result: IContactResponse = await intellipush.contact.create(contact)
console.log(result.data.name)
const contact = new ContactModel({
name: 'Tim Cook',
countrycode: '0047',
phonenumber: '12345678'
})
contact.setName('Howard Stewart')
const result: IContactResponse = await intellipush.contact.create(contact)
console.log(result.data.name)
Since the Data Models is really just an object, you can also pass an object directly to the API methods:
const result: IContactResponse = await intellipush.contact.create({
name: 'Tim Cook',
countrycode: '0047',
phonenumber: '12345678'
})
console.log(result.data.name)
- Authentication
- authenticate
- getToken
- setToken
- API Resources
- Contact
- create
- update
- get
- getContacts
- delete
- ContactList
- create
- update
- get
- getContactLists
- getContactsInList
- addContact
- removeContact
- delete
- SMS
- create
- createScheduled
- createBatch
- getPlanned
- getSent
- getUnsent
- getReceived
- status
- delete
- TwoFactor
- generate
- validate
- Url
- generate
- generateChild
- details
- User
- me
- Contact
Need help? Feel free to contact us.