Skip to content

Commit

Permalink
feat(state): Add reply helper to state
Browse files Browse the repository at this point in the history
  • Loading branch information
timkinnane committed Aug 12, 2018
1 parent 91aa16c commit 36aa269
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib/state.spec.ts
Expand Up @@ -139,6 +139,19 @@ describe('[state]', () => {
expect(b.envelopes![0].strings).to.eql(['testing'])
})
})
describe('.reply', () => {
it('prefixes all strings with @user from message', async () => {
const b = new bot.State({ message })
const respond = sinon.stub(b, 'respond')
await b.reply('one', { foo: 'bar' }, 'two')
sinon.assert.calledWithExactly(
respond,
'@test-user one',
{ foo: 'bar' },
'@test-user two'
)
})
})
describe('.respondVia', () => {
it('updates state method before calling respond', async () => {
const b = new bot.State({ message })
Expand Down
10 changes: 10 additions & 0 deletions src/lib/state.ts
Expand Up @@ -139,6 +139,16 @@ export class State implements IState {
return bot.respond(this)
}

/** Respond with the incoming message's user name prefixed */
reply (...content: any[]) {
for (let i in content) {
if (typeof content[i] === 'string') {
content[i] = `@${this.message.user.name} ${content[i]}`
}
}
return this.respond(...content)
}

/** Set method for dispatching envelope responding to state */
respondVia (method: string, ...content: any[]) {
this.respondEnvelope().via(method)
Expand Down

0 comments on commit 36aa269

Please sign in to comment.