Skip to content

Commit

Permalink
feat(channels): add conversation.started event (#266)
Browse files Browse the repository at this point in the history
* feat(channels): conversation.started

* fix
  • Loading branch information
samuelmasse committed Dec 3, 2021
1 parent 8417ec0 commit 67906da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
22 changes: 18 additions & 4 deletions packages/server/src/channels/base/conduit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ export abstract class ConduitInstance<TConfig, TContext extends ChannelContext<a
}
}

async receive<T>(payload: T) {
async receive<T>(payload: T, started?: boolean) {
const conduit = (await this.app.conduits.get(this.conduitId))!
const channel = this.app.channels.getById(conduit!.channelId)
const provider = (await this.app.providers.getById(conduit.providerId))!
const endpoint = await this.extractEndpoint(payload)

Expand All @@ -96,9 +97,22 @@ export abstract class ConduitInstance<TConfig, TContext extends ChannelContext<a
}

const { userId, conversationId } = await this.app.mapping.getMapping(clientId, conduit.channelId, endpoint)
return this.app.messages.create(conversationId, userId, endpoint.content, {
conduit: { id: this.conduitId, endpoint: _.omit(endpoint, 'content') }
})

if (started) {
await this.app.stream.stream(
'conversation.started',
{ conversationId, channel: channel.name },
clientId,
userId,
{
conduit: { id: this.conduitId, endpoint }
}
)
} else {
return this.app.messages.create(conversationId, userId, endpoint.content, {
conduit: { id: this.conduitId, endpoint: _.omit(endpoint, 'content') }
})
}
}

async initialize() {}
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/channels/teams/conduit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export class TeamsConduit extends ConduitInstance<TeamsConfig, TeamsContext> {
await turnContext.sendActivity(message)
})
}

await this.receive(turnContext, true)
}

protected async getContext(base: ChannelContext<any>): Promise<TeamsContext> {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/stream/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class StreamService extends Service {
}
}

private async stream(type: string, data: any, clientId: uuid, userId?: uuid, source?: ActionSource) {
async stream(type: string, data: any, clientId: uuid, userId?: uuid, source?: ActionSource) {
const payload = {
type,
data: {
Expand Down

0 comments on commit 67906da

Please sign in to comment.