I would like to know how to create a context dialog, but I don't think anything about how to make this request... can anyone help me?
i'm using a lib sdk dialogflow
I searched how to do this, but I don't find anything, I don't know how to implement this..
me code
class DialogFlowController {
public dialogID: string
public sessionID: string
public sessionClient: SessionsClient
constructor () {
this.dialogID = 'chatbot-asxj'
this.sessionID = v4()
this.sessionClient = new dialogflow.SessionsClient({
credentials: {
type: config.gooogleType,
client_id: config.googleClientId,
private_key: config.googlePrivateKey,
client_email: config.googleCLientEmail,
token_url: config.googleTokenUrl
}
})
}
public async interactor (req: Request, res: Response): Promise<Response> {
console.log(teste)
const messagem = req.body.goMessage
try {
// Create a new session
const sessionPath = this.sessionClient.projectAgentSessionPath(this.dialogID, this.sessionID)
const request = {
session: sessionPath,
queryInput: {
text: {
// The query to send to the dialogflow agent
text: messagem,
// The language used by the client (en-US)
languageCode: 'en-US'
}
}
}
const response = await this.sessionClient.detectIntent(request)
Socket.io.emit('returnMessage', response[0].queryResult?.fulfillmentText)
return res.status(200).json()
} catch (err) {
return res.status(500).json(err)
}
}
}