polyv-live-cli
Version:
CLI tool for managing PolyV live streaming services.
253 lines • 8.57 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.QaQuestionnaireServiceSdk = void 0;
const polyv_live_api_sdk_1 = require("polyv-live-api-sdk");
const errors_1 = require("../utils/errors");
class QaQuestionnaireServiceSdk {
constructor(authConfig, _serviceConfig) {
this.client = new polyv_live_api_sdk_1.PolyVClient(authConfig);
this.liveInteraction = this.client.liveInteraction;
}
async sendQa(params) {
try {
const result = await this.liveInteraction.sendQuestion({
channelId: params.channelId,
questionId: params.questionId,
duration: params.duration,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'sendQa');
}
}
async listQa(params) {
try {
const result = await this.liveInteraction.listQuestion({
channelId: params.channelId,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'listQa');
}
}
async stopQa(params) {
try {
const result = await this.liveInteraction.stopQuestion({
channelId: params.channelId,
questionId: params.questionId,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'stopQa');
}
}
async listQuestionSendTime(params) {
try {
const result = await this.liveInteraction.listQuestionSendTime({
channelId: params.channelId,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'listQuestionSendTime');
}
}
async getAnswerList(params) {
try {
const result = await this.liveInteraction.getAnswerList({
channelId: params.channelId,
sessionId: params.sessionId,
startDate: params.startDate,
endDate: params.endDate,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'getAnswerList');
}
}
async getQuestionList(params) {
try {
const result = await this.liveInteraction.getQuestionList(params.channelId, {
begin: params.begin,
end: params.end,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'getQuestionList');
}
}
async addEditQuestion(params) {
try {
const result = await this.liveInteraction.addEditQuestion(this.toSdkQuestion(params));
return result;
}
catch (error) {
throw this.wrapError(error, 'addEditQuestion');
}
}
async deleteQuestion(params) {
try {
const result = await this.liveInteraction.deleteQuestion({
channelId: params.channelId,
questionId: params.questionId,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'deleteQuestion');
}
}
async sendQuestionResult(params) {
try {
const result = await this.liveInteraction.sendQuestionResult({
channelId: params.channelId,
questionId: params.questionId,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'sendQuestionResult');
}
}
async createQuestionnaire(params) {
try {
const result = await this.liveInteraction.createQuestionnaire({
channelId: params.channelId,
questionnaireTitle: params.title,
customQuestionnaireId: params.customQuestionnaireId,
autoPublishTime: params.autoPublishTime,
autoEndTime: params.autoEndTime,
privacyEnabled: params.privacyEnabled,
privacyContent: params.privacyContent,
questions: params.questions.map(q => this.toSdkQuestionnaireQuestion(q)),
});
return result;
}
catch (error) {
throw this.wrapError(error, 'createQuestionnaire');
}
}
toSdkQuestionnaireQuestion(question) {
const sdkQuestion = {
name: question.name,
type: question.type,
options: question.options,
answer: question.answer,
scoreEnabled: question.scoreEnabled,
score: question.score,
required: question.required,
};
if (question.options && question.options.length > 0) {
sdkQuestion.optionList = question.options.map((name, index) => ({
id: String(index + 1),
name,
}));
question.options.slice(0, 10).forEach((option, index) => {
sdkQuestion[`option${index + 1}`] = option;
});
}
return sdkQuestion;
}
async listQuestionnaires(params) {
try {
const result = await this.liveInteraction.listQuestionnaireByPage({
channelId: params.channelId,
page: params.page,
pageSize: params.pageSize,
sessionId: params.sessionId,
startDate: params.startDate,
endDate: params.endDate,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'listQuestionnaires');
}
}
async listQuestionnaire(params) {
try {
const result = await this.liveInteraction.listQuestionnaire({
channelId: params.channelId,
startTime: params.startTime,
endTime: params.endTime,
page: params.page,
pageSize: params.pageSize,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'listQuestionnaire');
}
}
async getQuestionnaireDetail(params) {
try {
const result = await this.liveInteraction.getQuestionnaireDetail({
channelId: params.channelId,
questionnaireId: params.questionnaireId,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'getQuestionnaireDetail');
}
}
async getQuestionnaireResult(params) {
try {
const result = await this.liveInteraction.getQuestionnaireResult({
channelId: params.channelId,
questionnaireId: params.questionnaireId,
sessionId: params.sessionId,
startDate: params.startDate,
endDate: params.endDate,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'getQuestionnaireResult');
}
}
async batchCreateQuestionnaire(params) {
try {
const result = await this.liveInteraction.batchCreateQuestionnaire({
questionnaires: params.questionnaires,
});
return result;
}
catch (error) {
throw this.wrapError(error, 'batchCreateQuestionnaire');
}
}
toSdkQuestion(params) {
const question = {
channelId: params.channelId,
type: params.type,
answer: params.answer,
name: params.name,
itemType: params.itemType,
};
if (params.questionId !== undefined) {
question.questionId = params.questionId;
}
params.options?.slice(0, 15).forEach((option, index) => {
question[`option${index + 1}`] = option;
});
params.tips?.slice(0, 5).forEach((tip, index) => {
question[`tips${index + 1}`] = tip;
});
return question;
}
wrapError(error, operation) {
if (error instanceof errors_1.PolyVError) {
return error;
}
const message = error instanceof Error ? error.message : String(error);
return new errors_1.PolyVError(`${operation} failed: ${message}`, 'QA_QUESTIONNAIRE_API_ERROR', 1, { originalError: error });
}
}
exports.QaQuestionnaireServiceSdk = QaQuestionnaireServiceSdk;
//# sourceMappingURL=qa-questionnaire-service.js.map