botact
Advanced tools
Comparing version 2.3.9 to 2.4.0
@@ -6,3 +6,3 @@ const axios = require('axios') | ||
if (!options.v) { | ||
options.v = (this.settings && this.settings.v) || 5.73 | ||
options.v = (this.settings && this.settings.v) || 5.78 | ||
} | ||
@@ -9,0 +9,0 @@ |
@@ -73,4 +73,4 @@ const { RedisClient, createClient, Multi } = require('redis') | ||
reply (user_id, message, attachment) { | ||
return this.reply(user_id, message, attachment) | ||
reply (user_id, message, attachment, keyboard) { | ||
return this.reply(user_id, message, attachment, keyboard) | ||
} | ||
@@ -77,0 +77,0 @@ |
@@ -38,8 +38,8 @@ module.exports = async function (req, res, callback) { | ||
scene: { | ||
join: (scene, body, step, instantly) => this.joinScene(ctx, scene, body, step, instantly), | ||
next: (body) => this.nextScene(ctx, body), | ||
join: (...args) => this.joinScene(ctx, ...args), | ||
next: (...args) => this.nextScene(ctx, ...args), | ||
leave: () => this.leaveScene(ctx) | ||
}, | ||
reply: (message, attachment) => this.reply(user_id, message, attachment), | ||
sendMessage: (user_id, message, attachment) => this.reply(user_id, message, attachment) | ||
reply: (...args) => this.reply(user_id, ...args), | ||
sendMessage: this.reply | ||
} | ||
@@ -46,0 +46,0 @@ |
@@ -1,2 +0,2 @@ | ||
module.exports = function (user_id, message, attachment) { | ||
module.exports = function (user_id, message, attachment, keyboard) { | ||
return new Promise((resolve, reject) => { | ||
@@ -6,3 +6,15 @@ this.execute('messages.send', { | ||
message, | ||
attachment | ||
attachment, | ||
keyboard: keyboard | ||
? JSON.stringify({ | ||
...keyboard, | ||
buttons: keyboard.buttons.map(item => item.map((item) => ({ | ||
...item, | ||
action: { | ||
...item.action, | ||
payload: JSON.stringify(item.action.payload) | ||
} | ||
}))) | ||
}) | ||
: null | ||
}, ({ response, error }) => { | ||
@@ -9,0 +21,0 @@ if (error) { |
{ | ||
"name": "botact", | ||
"version": "2.3.9", | ||
"version": "2.4.0", | ||
"description": "Botact enables developers to focus on writing reusable application logic instead of spending time building infrastructure.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -64,3 +64,3 @@ [![botact](https://img.shields.io/npm/v/botact.svg?style=flat-square)](https://www.npmjs.com/package/botact/) [![botact](https://img.shields.io/node/v/botact.svg?style=flat-square)](https://nodejs.org/en/) [![botact](https://img.shields.io/npm/dm/botact.svg?style=flat-square)](https://www.npmjs.com/package/botact/) [![botact](https://img.shields.io/travis/bifot/botact.svg?branch=master&style=flat-square)](https://travis-ci.org/bifot/botact/) [![botact](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/) | ||
- [.execute(method, settings, callback)](#executemethod-settings-callback) | ||
- [.reply(user_id, message, attachment)](#replyuser_id-message-attachment) | ||
- [.reply(user_id, message, attachment, keyboard)](#replyuser_id-message-attachment-keyboard) | ||
- [.listen(req, res, callback)](#listenreq-res-callback) | ||
@@ -174,3 +174,3 @@ | ||
### .reply(user_id, message, attachment) | ||
### .reply(user_id, message, attachment, keyboard) | ||
@@ -185,3 +185,4 @@ Sends message to user | ||
message: string, // required, if attachment not setten | ||
attachment: string // required, if message not setten | ||
attachment: string, // required, if message not setten | ||
keyboard: Object // optional | ||
): Promise<any> // Promise with response/error | ||
@@ -194,7 +195,25 @@ ``` | ||
bot.command('start', (ctx) => { | ||
// with shortcut from context | ||
// via shortcut from context | ||
ctx.reply('Hi, this is start!') | ||
// function from context | ||
// via shortcut with keyboard | ||
ctx.reply('Yo, this is keyboard?', null, { | ||
one_time: false, | ||
buttons: [ | ||
[ | ||
{ | ||
action: { | ||
type: 'text', | ||
payload: { | ||
button: 'Hello, world!' | ||
}, | ||
label: 'Hello, world!' | ||
}, | ||
color: 'primary' | ||
} | ||
] | ||
] | ||
}) | ||
// via function from context | ||
ctx.sendMessage(ctx.user_id, 'Hi, this is start!') | ||
// simple usage | ||
// via function from instance | ||
bot.reply(ctx.user_id, 'Hi, this is start!') | ||
@@ -214,4 +233,4 @@ // to multiple users | ||
listen ( | ||
req: any, // Express request, required | ||
res: any // Express response, required | ||
req: any, // Express request, required | ||
res: any // Express response, required | ||
callback: function // Callback for errors | ||
@@ -218,0 +237,0 @@ ) |
@@ -43,2 +43,26 @@ const { expect } = require('chai') | ||
it('reply with keyboard', async () => { | ||
const { response, error } = await bot.reply(145003487, 'This is button', null, { | ||
one_time: false, | ||
buttons: [ | ||
[ | ||
{ | ||
action: { | ||
type: 'text', | ||
payload: { | ||
button: 'Hello, world!' | ||
}, | ||
label: 'Hello, world!' | ||
}, | ||
color: 'primary' | ||
} | ||
] | ||
] | ||
}) | ||
const [ message ] = response | ||
expect(response).to.be.a('array') | ||
expect(message).to.be.a('object').to.have.all.keys([ 'peer_id', 'message_id' ]) | ||
}) | ||
it('reply without message or attachment', async () => { | ||
@@ -45,0 +69,0 @@ try { |
704153
44
1029
704