Reputation: 151
I have made a bot in v4 framework using c#. I want to save the entire conversation into a storage , in a readable format . Our requirement is to save the bot conversation in a readable format or plain text. In my case only user info is getting saved not the conversation between user and the bot.
Upvotes: 1
Views: 119
Reputation: 363
you can use below code
I have worked on nodejs but it should be similar to C#.
For each step call the logActivity
const { preserveService } = require('../../../Service/dbService');
await preserveService.logActivity(step.context, userData,Any param);
logActivity : async function (turnContext, userData,Any param){
try{
let userInfo = await userDataUtil.getUserInfo(turnContext,userData);
colNameAndValueArray = [
{
[PROPERTY_NAME.COLUMN_NAME] : 'response_from',
[PROPERTY_NAME.VALUE] : responsefrom,
[PROPERTY_NAME.DATATYPE] : DATATYPE.STRING
},
{
[PROPERTY_NAME.COLUMN_NAME] : 'user_session_id',
[PROPERTY_NAME.VALUE] : userInfo.userId,
[PROPERTY_NAME.DATATYPE] : DATATYPE.STRING
},
{
//conversation_id
[PROPERTY_NAME.COLUMN_NAME] : 'conversation_id',
[PROPERTY_NAME.VALUE] : turnContext._activity.conversation.id,
[PROPERTY_NAME.DATATYPE] : DATATYPE.STRING
},
{
[PROPERTY_NAME.COLUMN_NAME] : 'is_answered',
[PROPERTY_NAME.VALUE] : isAnswered,
[PROPERTY_NAME.DATATYPE] : DATATYPE.BOOLEAN
}
]
await this.insert(CONFIG.DB.AUDIT_TABLE, colNameAndValueArray);
}catch(err){
console.log(`------------------------`);
console.log(`Error occurred while inserting audit logs`);
console.log(err);
console.log(`------------------------`);
}}
insert : async function(tableName, colNameAndValueArray, returnColumnName){
let query = null;
try{
if(util.isNotEmptyString(tableName) && util.isNotEmptyArray(colNameAndValueArray)){
let columnNames = dbUtil.getColNames(colNameAndValueArray);
let columnValues = dbUtil.getColValues(colNameAndValueArray);
if(columnNames == null || columnValues == null){
throw new Error('Invalid column name or value. Kindly check the value you have passed');
}
query = `INSERT INTO ${tableName} (${columnNames}) VALUES (${columnValues}) ${util.isNotEmptyString(returnColumnName)? ` RETURNING ${returnColumnName}`: ''}`;
console.log(`------------------------`);
console.log(`Query : ${query}`);
console.log(`------------------------`);
return this.executeQuery(query);
}else{
return Promise.reject(REQUIRED_PARAMETER_MISSING);
}
}catch(err){
console.log(`------------------------`);
console.log(`Error occurred while executing insert query : ${ query != null ? query : '' }`);
console.log(err);
console.log(`------------------------`);
return Promise.reject(err);
}}
Hope this helps
Sanjeev Guatam
Upvotes: 0
Reputation: 1577
You can use a middleware for that: TranscriptLoggerMiddleware
More info on middlewares
The middleware will handle saving transcript for you in a storage.
Upvotes: 4