@thoughtspot/visual-embed-sdk
Version:
ThoughtSpot Embed SDK
78 lines • 2.63 kB
JavaScript
import { graphqlQuery } from '../graphql-request';
import * as queries from './conversation-queries';
export class Conversation {
constructor(thoughtSpotHost, worksheetId) {
this.thoughtSpotHost = thoughtSpotHost;
this.worksheetId = worksheetId;
this.inProgress = null;
this.inProgress = this.init();
}
async init() {
const { convId } = await this.createConversation();
this.conversationId = convId;
}
createConversation() {
return this.executeQuery(queries.createConversation, {
params: {
initialCtx: {
tsWorksheetCtx: {
worksheet: {
worksheetId: this.worksheetId,
},
},
type: 'TS_WORKSHEET',
},
userInfo: {
tenantUrl: `${this.thoughtSpotHost}/prism`,
},
},
});
}
async sendMessage(userMessage) {
await this.inProgress;
try {
const { responses } = await this.executeQuery(queries.sendMessage, {
params: {
convId: this.conversationId,
headers: [],
msg: {
data: {
userCmdData: {
cmdText: userMessage,
nlsData: {
worksheetId: this.worksheetId,
questionType: 'ANSWER_SPEC_GENERATION',
},
},
},
msgId: crypto.randomUUID(),
type: 'USER_COMMAND',
},
},
});
const data = responses[0].data;
return {
convId: this.conversationId,
messageId: responses[0].msgId,
data: {
...data.asstRespData.nlsAnsData.sageQuerySuggestions[0],
convId: this.conversationId,
messageId: responses[0].msgId,
},
error: null,
};
}
catch (error) {
return { error };
}
}
async executeQuery(query, variables) {
return graphqlQuery({
query,
variables,
thoughtSpotHost: this.thoughtSpotHost,
isCompositeQuery: false,
});
}
}
//# sourceMappingURL=conversation-service.js.map