Skip to content

Commit

Permalink
feat(sms): add params to send SMS scheduled (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
caioagiani authored Jan 26, 2022
1 parent ef83522 commit 63e57da
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
35 changes: 35 additions & 0 deletions __tests__/sms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,41 @@ describe('Mobizon sms methods', () => {
expect(code).toBe(0);
});

it('should send SMS scheduled', async () => {
const deferredToTs = new Date()
.toISOString()
.replace('T', ' ')
.slice(0, 19);

const {
code,
data: { status },
} = await mobizon.sendSms({
...dataSms,
params: {
name: 'Campaign scheduled.',
deferredToTs,
},
});

expect(code).toBe(0);
expect(status).toBe(2);
});

it('should display an error send SMS scheduled', async () => {
const { code, message } = await mobizon.sendSms({
...dataSms,
params: {
deferredToTs: new Date(),
},
});

expect(code).toBe(1);
expect(message).toBe(
'Um ou mais campos contêm dados incorretos. Verifique os erros e tente novamente.'
);
});

it('should display an error when creating sms with invalid key', async () => {
setConfig({ apiKey: 'invalid_key' });

Expand Down
13 changes: 13 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ mobizon.setConfig({

console.log(sendSms);

/** Enviar SMS agendado */
const sendSmsScheduled = await mobizon.sendSms({
recipient: process.env.NUMBER,
from: '',
text: 'SMS sent by Mobizon (scheduled).',
params: {
name: 'SMS Scheduled',
deferredToTs: '2022-01-26 01:00:00',
},
});

console.log(sendSmsScheduled);

/** Listar todos os SMS enviados */
const listSms = await mobizon.listSms({
criteria: {
Expand Down
10 changes: 8 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export declare namespace mobizon {
function listSms(data: PayloadListSMS): Promise<ListSMS>;

/** StatusSMS */
type StatusSMS =
type StatusSMS =
'DELIVRD' |
'NEW' |
'ENQUEUD' |
Expand Down Expand Up @@ -87,7 +87,13 @@ export declare namespace mobizon {
export interface PayloadSendSMS {
recipient: string,
from: string,
text: string
text: string,
params?: {
name: string,
deferredToTs: string,
mclass: number,
validity: number
}
}

/** SendSMS */
Expand Down

0 comments on commit 63e57da

Please sign in to comment.