@castery/caster-telegram
Advanced tools
Comparing version
@@ -31,3 +31,3 @@ 'use strict'; | ||
*/ | ||
constructor(caster, context, id) { | ||
constructor(caster, { id, context, $text = null }) { | ||
super(caster); | ||
@@ -53,2 +53,3 @@ | ||
this.text = context.message.text; | ||
this.$text = $text; | ||
@@ -91,3 +92,6 @@ this.raw = context; | ||
const message = new TelegramMessageContext(this.caster, this.raw, this.platform.id); | ||
const message = new TelegramMessageContext(this.caster, { | ||
id: this.platform.id, | ||
context: this.raw | ||
}); | ||
@@ -100,5 +104,5 @@ message.to = this.from; | ||
options.attachments = [options.attachments]; | ||
} else { | ||
message.attachments = options.attachments; | ||
} | ||
message.attachments = options.attachments; | ||
} | ||
@@ -105,0 +109,0 @@ |
@@ -111,5 +111,7 @@ 'use strict'; | ||
async start() { | ||
const { id, username } = await this.telegram.getMe(); | ||
this.setOptions({ username }); | ||
if (this.options.id === null) { | ||
const { id } = await this.telegram.getMe(); | ||
this.setOptions({ id }); | ||
@@ -210,4 +212,14 @@ } | ||
this.telegraf.on('message', context => { | ||
let $text = context.message.text.replace(`@${this.options.username}`, ''); | ||
if ($text.startsWith('/')) { | ||
$text = $text.substring(1); | ||
} | ||
for (const caster of this._casters) { | ||
caster.dispatchIncoming(new _message.TelegramMessageContext(caster, context, this.options.id)); | ||
caster.dispatchIncoming(new _message.TelegramMessageContext(caster, { | ||
id: this.options.id, | ||
context, | ||
$text | ||
})); | ||
} | ||
@@ -214,0 +226,0 @@ }); |
@@ -57,2 +57,6 @@ 'use strict'; | ||
* @type {Object} | ||
* | ||
* @property {mixed} [id] Unique ID platform | ||
* @property {Object} [adapter] Options for adapter | ||
* @property {string} [username] Username bot | ||
*/ | ||
@@ -62,3 +66,5 @@ const defaultOptions = exports.defaultOptions = { | ||
adapter: {} | ||
adapter: {}, | ||
username: null | ||
}; | ||
@@ -76,3 +82,5 @@ | ||
adapter: _joi2.default.object() | ||
adapter: _joi2.default.object(), | ||
username: _joi2.default.string().allow(null) | ||
}); |
{ | ||
"name": "@castery/caster-telegram", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "🤖⛓️ The Telegram platform for caster", | ||
@@ -36,4 +36,4 @@ "main": "index.js", | ||
"babel-preset-env": "^1.6.0", | ||
"chai": "^4.1.0", | ||
"mocha": "^3.4.2" | ||
"chai": "^4.1.1", | ||
"mocha": "^3.5.0" | ||
}, | ||
@@ -43,3 +43,3 @@ "dependencies": { | ||
"bluebird": "^3.5.0", | ||
"debug": "^2.6.8", | ||
"debug": "^3.0.0", | ||
"joi": "^10.6.0", | ||
@@ -46,0 +46,0 @@ "telegraf": "^3.9.0" |
@@ -30,3 +30,3 @@ 'use strict'; | ||
*/ | ||
constructor (caster, context, id) { | ||
constructor (caster, { id, context, $text = null }) { | ||
super(caster); | ||
@@ -54,2 +54,3 @@ | ||
this.text = context.message.text; | ||
this.$text = $text; | ||
@@ -92,3 +93,6 @@ this.raw = context; | ||
const message = new TelegramMessageContext(this.caster, this.raw, this.platform.id); | ||
const message = new TelegramMessageContext(this.caster, { | ||
id: this.platform.id, | ||
context: this.raw | ||
}); | ||
@@ -101,5 +105,5 @@ message.to = this.from; | ||
options.attachments = [options.attachments]; | ||
} else { | ||
message.attachments = options.attachments; | ||
} | ||
message.attachments = options.attachments; | ||
} | ||
@@ -106,0 +110,0 @@ |
@@ -105,5 +105,7 @@ 'use strict'; | ||
async start () { | ||
const { id, username } = await this.telegram.getMe(); | ||
this.setOptions({ username }); | ||
if (this.options.id === null) { | ||
const { id } = await this.telegram.getMe(); | ||
this.setOptions({ id }); | ||
@@ -204,5 +206,15 @@ } | ||
this.telegraf.on('message', (context) => { | ||
let $text = context.message.text.replace(`@${this.options.username}`, ''); | ||
if ($text.startsWith('/')) { | ||
$text = $text.substring(1); | ||
} | ||
for (const caster of this._casters) { | ||
caster.dispatchIncoming( | ||
new TelegramMessageContext(caster, context, this.options.id) | ||
new TelegramMessageContext(caster, { | ||
id: this.options.id, | ||
context, | ||
$text | ||
}) | ||
); | ||
@@ -209,0 +221,0 @@ } |
@@ -48,2 +48,6 @@ 'use strict'; | ||
* @type {Object} | ||
* | ||
* @property {mixed} [id] Unique ID platform | ||
* @property {Object} [adapter] Options for adapter | ||
* @property {string} [username] Username bot | ||
*/ | ||
@@ -53,3 +57,5 @@ export const defaultOptions = { | ||
adapter: {} | ||
adapter: {}, | ||
username: null | ||
}; | ||
@@ -67,3 +73,5 @@ | ||
adapter: Joi.object() | ||
adapter: Joi.object(), | ||
username: Joi.string().allow(null), | ||
}); |
Sorry, the diff of this file is not supported yet
90213
1.07%717
5.91%+ Added
Updated