Skip to content
Permalink
Browse files

async/await

  • Loading branch information...
julioolvr committed Jun 15, 2016
1 parent 1686a61 commit 0b93835276b14a57c44c113bb12d70660e883085
Showing with 23 additions and 1 deletion.
  1. +3 −0 .babelrc
  2. +1 −0 index.js
  3. +2 −0 package.json
  4. +17 −1 src/bot.js
@@ -1,5 +1,8 @@
{
"presets": [
"es2015"
],
"plugins": [
"transform-async-to-generator"
]
}
@@ -4,6 +4,7 @@ dotenv.load()

var path = require('path')

require('babel-polyfill')
require('babel-register')

var Bot = require('./src/bot').default
@@ -11,6 +11,8 @@
"license": "ISC",
"dependencies": {
"babel": "^6.5.2",
"babel-plugin-transform-async-to-generator": "^6.8.0",
"babel-polyfill": "^6.9.1",
"babel-preset-es2015": "^6.9.0",
"babel-register": "^6.9.0",
"dotenv": "^2.0.0",
@@ -7,7 +7,23 @@ export default class Bot {

start() {
this.client.on('message', message => {
this.client.sendMessage(message.chat.id, message.text)
if (!message.reply_to_message) {
this.respondTo(message)
}
})
}

async respondTo(message) {
let text = text = message.text

while (text !== 'stop') {
let sentMessage = await this.client.sendMessage(message.chat.id,
`echo: ${text}`,
{ reply_markup: JSON.stringify({ force_reply: true }) })
let reply = await new Promise(resolve => this.client.onReplyToMessage(sentMessage.chat.id, sentMessage.message_id, resolve))
text = reply.text
}

this.client.sendMessage(message.chat.id, 'Stopping')
}
}

0 comments on commit 0b93835

Please sign in to comment.
You can’t perform that action at this time.