Skip to content

Commit

Permalink
fix: timeout fake event
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Marín committed Apr 30, 2019
1 parent e86ca6d commit dc16c5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/bp/core/services/dialog/janitor.ts
Expand Up @@ -53,14 +53,17 @@ export class DialogJanitor extends Janitor {

await Promise.mapSeries(sessionsIds, async id => {
try {
const channel = SessionIdFactory.createChannelFromId(id)
const target = SessionIdFactory.createTargetFromId(id)
const threadId = SessionIdFactory.createThreadIdFromId(id)
const session = await this.sessionRepo.get(id)

// This event only exists so that processTimeout can call processEvent
const fakeEvent = Event({
type: 'timeout',
channel: id.substring(0, id.indexOf('::')),
channel: channel,
target: target,
threadId: threadId,
direction: 'incoming',
payload: '',
botId: botId
Expand Down
8 changes: 8 additions & 0 deletions src/bp/core/services/dialog/session/id-factory.ts
Expand Up @@ -6,7 +6,15 @@ export class SessionIdFactory {
return `${channel}::${target}${threadId ? `::${threadId}` : ''}`
}

static createChannelFromId(sessionId: string) {
return sessionId.split('::')[0]
}

static createTargetFromId(sessionId: string) {
return sessionId.split('::')[1]
}

static createThreadIdFromId(sessionId: string) {
return sessionId.split('::')[2]
}
}

0 comments on commit dc16c5b

Please sign in to comment.