Skip to content

Commit

Permalink
feat: add question answer module
Browse files Browse the repository at this point in the history
Signed-off-by: Sai Ranjit Tummalapalli <sairanjit.tummalapalli@ayanworks.com>
  • Loading branch information
sairanjit committed Feb 21, 2024
1 parent c847132 commit 2899b4b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 45 deletions.
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 the question record with the given id.
*
* @param agent The agent instance.
* @param query The query to use to find the question record.
*/
export const getQuestion = 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.

0 comments on commit 2899b4b

Please sign in to comment.