1.11.0 • Published 3 months ago
wildix-pbx-sdk v1.11.0
Wildix PBX SDK
Wildix PBX API library
install
npm i wildix-pbx-sdk
or
yarn add wildix-pbx-sdk
import classes
import {
AuthService,
BasicAuth,
ColleagueFields,
GetColleagueByIdRequest,
GetColleaguesRequest,
GetUserPersonalInfoRequest,
GetUserPersonalTokenRequest,
JwtTokenAuth,
PbxClient,
PbxFetchError,
S2sAuth,
UpdateColleagueByIdRequest,
AuthDomains
} from 'wildix-pbx-sdk';
Create PbxClient instance
with Basic authorization
const pbxClient = new PbxClient({
pbxDomain: 'pbx-domain',
userAuth: new BasicAuth({
extension: '100',
password: 'password',
})
});
or JWT token authorization
const pbxClient = new PbxClient({
pbxDomain: 'pbx-domain',
userAuth: new JwtTokenAuth({
token: 'access_JPn9oXg8LDVSdcwsCpeKqFXL89.....',
type: 'simple',
})
});
or Server2Server (s2s) authorization
const pbxClient = new PbxClient({
pbxDomain: 'pbx-domain',
userAuth: new S2sAuth({
appId: 's2s-app-id',
appSecret: 's2s-app-secret',
appName: 's2s-app-name',
})
});
Usage
try {
// get personal user info
const personalInfo = await pbxClient.apiRequest(new GetUserPersonalInfoRequest([
ColleagueFields.ID,
ColleagueFields.NAME,
]));
console.log({personalInfo})
// get personal user token
const personalToken = await pbxClient.apiRequest(new GetUserPersonalTokenRequest(AuthDomains.STAGE));
console.log({personalToken})
// get colleaguse
const colleagues: GetColleaguesResponse = await pbxClient.apiRequest(new GetColleaguesRequest({
count: 2,
fields: [
ColleagueFields.ID,
ColleagueFields.EXTENSION,
ColleagueFields.EMAIL,
]
}));
console.log(colleagues.records)
// get colleague by id
const colleague: GetColleagueResponse = await pbxClient.apiRequest(new GetColleagueByIdRequest({
id: '1135500',
fields: [
ColleagueFields.ID,
ColleagueFields.EXTENSION,
ColleagueFields.EMAIL,
]
}));
console.log({colleague})
// colleague update
const colleagueUpdated: UpdateColleagueResponse = await pbxClient.apiRequest(new UpdateColleagueByIdRequest({
id: '1135500',
fields: {
[ColleagueFields.NAME]: 'test_' + Date.now(),
}
}));
console.log({colleagueUpdated})
} catch (e) {
console.error(e.message);
}
or you can make any other authorized request to the PBX
const conferenceResponse = await pbxClient.authorizedPbxRequest(
'/api/v1/VideoConference/Rooms/',
{
method: 'post',
body: JSON.stringify({
'subject': 'Test Conference - ' + new Date().toISOString(),
'participants': [{
'type': 'colleague',
'name': 'my test',
'jid': '999@x-hoppers-us.wildixin.com',
'email': 'vladimir.gorobets@gmail.com'
}],
'schedule': {
'enabled': true,
'start': '20\/10\/2023 09:00',
'end': '20\/10\/2023 10:00',
'timezone': 'Europe\/Kiev',
'recurrence': '',
'description': 'x-streamConnect Test Conference',
'country': 'US',
'lang': 'en-us',
'dialInNumbers': ['en-us']
}
})
}
)
console.log({conferenceResponse});
Wildix Authorization service
If you want to receive OpenId JWT token for Wildix microservices
const authService: AuthService = new AuthService({
authDomain: AuthDomains.STAGE
});
// get token for Wildix microservice
const serviceToken = await authService.getOpenIdTokenForService(pbxClient, 'https://geo.wildix.com', 'get all');
console.log({serviceToken});