Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge feature to support basic message for a multi-tenant agent #4

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/controllers/multi-tenancy/MultiTenancyController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@
private async handleKey(createDidOptions: DidCreate, tenantId: string) {
let didResponse
let did: string
let didDocument: any

Check warning on line 392 in src/controllers/multi-tenancy/MultiTenancyController.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected any. Specify a different type

await this.agent.modules.tenants.withTenantAgent({ tenantId }, async (tenantAgent) => {
if (!createDidOptions.seed) {
Expand Down Expand Up @@ -444,7 +444,7 @@

private async handleDidPeer(createDidOptions: DidCreate, tenantId: string) {
let didResponse
let did: any

Check warning on line 447 in src/controllers/multi-tenancy/MultiTenancyController.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected any. Specify a different type

if (!createDidOptions.keyType) {
throw Error('keyType is required')
Expand Down Expand Up @@ -478,7 +478,7 @@

private async handleWeb(createDidOptions: DidCreate, tenantId: string) {
let did
let didDocument: any

Check warning on line 481 in src/controllers/multi-tenancy/MultiTenancyController.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected any. Specify a different type

if (!createDidOptions.domain) {
throw Error('For web method domain is required')
Expand Down Expand Up @@ -833,7 +833,7 @@
outOfBandRecords = await tenantAgent.oob.getAll()

if (invitationId)
outOfBandRecords = outOfBandRecords.filter((o: any) => o.outOfBandInvitation.id === invitationId)

Check warning on line 836 in src/controllers/multi-tenancy/MultiTenancyController.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected any. Specify a different type
outOfBandRecordsRes = outOfBandRecords.map((c: any) => c.toJSON())
})

Expand Down Expand Up @@ -1007,7 +1007,7 @@
schema,
})
})

if (schemaResponse.schemaState?.state === 'failed') {
const reason = schemaResponse.schemaState?.reason?.toLowerCase()
if (reason && reason.includes('insufficient') && reason.includes('funds')) {
Expand Down Expand Up @@ -2013,4 +2013,35 @@

return questionAnswerRecord
}

/**
* Send a question to a connection
*
* @param tenantId Tenant identifier
* @param connectionId Connection identifier
* @param content The content of the message
*/
@Security('apiKey')
@Post('/basic-message/:connectionId/:tenantId')
public async sendBasicMessage(
@Path('connectionId') connectionId: RecordId,
@Path('tenantId') tenantId: string,
@Body() request: Record<'content', string>,
@Res() notFoundError: TsoaResponse<404, { reason: string }>,
@Res() internalServerError: TsoaResponse<500, { message: string }>
) {
try {
let basicMessageRecord
await this.agent.modules.tenants.withTenantAgent({ tenantId }, async (tenantAgent) => {
basicMessageRecord = await tenantAgent.basicMessages.sendMessage(connectionId, request.content)
basicMessageRecord = basicMessageRecord?.toJSON()
})
return basicMessageRecord
} catch (error) {
if (error instanceof RecordNotFoundError) {
return notFoundError(404, { reason: `connection with connection id "${connectionId}" not found.` })
}
return internalServerError(500, { message: `something went wrong: ${error}` })
}
}
}
Loading