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

feat: add question answer module #21

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/ssi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@aries-framework/core": "0.4.2",
"@aries-framework/indy-vdr": "0.4.2",
"@aries-framework/push-notifications": "^0.6.0",
"@aries-framework/question-answer": "0.4.2",
"@aries-framework/react-hooks": "0.5.0",
"@aries-framework/react-native": "0.4.2"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/ssi/src/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
IndyVdrSovDidResolver
} from '@aries-framework/indy-vdr'
import { PushNotificationsFcmModule } from '@aries-framework/push-notifications'
import { QuestionAnswerModule } from '@aries-framework/question-answer'
import { agentDependencies } from '@aries-framework/react-native'
import { anoncreds } from '@hyperledger/anoncreds-react-native'
import { ariesAskar } from '@hyperledger/aries-askar-react-native'
Expand Down Expand Up @@ -99,7 +100,8 @@ export const getAgentModules = (
connections: new ConnectionsModule({
autoAcceptConnections: true
}),
pushNotificationsFcm: new PushNotificationsFcmModule()
pushNotificationsFcm: new PushNotificationsFcmModule(),
questionAnswer: new QuestionAnswerModule()
}
}

Expand Down
7 changes: 5 additions & 2 deletions packages/ssi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ import {
ConnectionEventTypes,
CredentialEventTypes,
ProofEventTypes,
Query
Query,
utils
} from '@aries-framework/core'
import {
GetCredentialsForRequestReturn,
Expand All @@ -103,6 +104,7 @@ export * from './proofs'
export * from './basicMessages'
export * from './pushNotifications'
export * from './genericRecords'
export * from './questionAnswer'
// Core
export {
LogLevel,
Expand Down Expand Up @@ -152,7 +154,8 @@ export {
ProofEventTypes,
GenericRecord,
SaveGenericRecordOption,
Query
Query,
utils
}
// Anoncreds
export {
Expand Down
1 change: 1 addition & 0 deletions packages/ssi/src/questionAnswer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './questionAnswer'
50 changes: 50 additions & 0 deletions packages/ssi/src/questionAnswer/questionAnswer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { Agent, Query } from '@aries-framework/core'
import type { QuestionAnswerRecord, ValidResponse } from '@aries-framework/question-answer'

export type SendQuestionConfig = {
question: string
validResponses: ValidResponse[]
detail?: string
}

/**
* Sends a question to the connection with the given connection id.
*
* @param agent The agent instance .
* @param connectionId The connection id.
* @param config The question to send.
*/
export const sendQuestion = async (agent: Agent, connectionId: string, config: SendQuestionConfig) => {
return agent.modules.questionAnswer.sendQuestion(connectionId, config)
}

/**
* Sends an answer to the question with the given question record id.
*
* @param agent The agent instance.
* @param questionRecordId The question record id.
* @param response The response to send.
*/
export const sendAnswer = async (agent: Agent, questionRecordId: string, response: string) => {
return agent.modules.questionAnswer.sendAnswer(questionRecordId, response)
}

/**
* Retrieves all question answer records that match the given query.
*
* @param agent The agent instance.
* @param query The query to use to find the question record.
*/
export const getAllQuestionAnswerRecords = async (agent: Agent, query: Query<QuestionAnswerRecord>) => {
return agent.modules.questionAnswer.findAllByQuery(query)
}

/**
* Retrieves the question answer record with the given id.
*
* @param agent The agent instance.
* @param questionAnswerRecordId The question record id.
*/
export const getQuestionAnswerRecordById = async (agent: Agent, questionRecordId: string) => {
return agent.modules.questionAnswer.findById(questionRecordId)
}
49 changes: 7 additions & 42 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading