Nep
07/03/2024, 10:46 PMvapi.on("message", (message) => {
if (message.transcriptType == "final") {
if (message.role == "assistant") {
setConversationLog(conversationLog => [...conversationLog, { question, answer: message.transcript }]);
console.log(message);
}
}
});
{type: 'transcript', role: 'assistant', transcriptType: 'final', transcript: 'Hi there. What question matters most to you now?'}
role: "assistant"
transcript: "Hi there. What question matters most to you now?"
transcriptType: "final"
type: "transcript"
[[Prototype]]: Object
2) If I send an additional message containing background information using vapi.send, shouldn't I get a response back in the message object thingy? I'm getting nothing back, but I want to know if and when my message gets received. Again, here's sample code...
vapi.on("call-start", () => {
vapi.send({
type: "add-message",
message: {
role: "system",
content: conversationString,
},
});
});
vapi.on("message", (message) => {
if (message.type == "conversation-update") {
console.log("Received message:", message);
}
});
Vapi
07/03/2024, 10:48 PMvapi.send
, you should indeed expect a response back in the message object. If you're not receiving any, it could be due to the message not being processed correctly by the server or an issue with the event listener not being triggered. Make sure that the message type you're listening for ("conversation-update"
) matches the type of message the server sends as a response. If the server sends a different type, you'll need to listen for that specific type instead. If you've confirmed that the message type is correct and you're still not receiving a response, please ask support for more info on this.
For both issues, it's also a good idea to check the network activity using browser developer tools to ensure that messages are being sent and received as expected. If you need further assistance, don't hesitate to reach out to support.Vapi
07/03/2024, 10:48 PMSahil
07/04/2024, 4:53 PMShubham Bajaj
07/05/2024, 12:46 PMconsole.log(JSON.stringify(message))
to see a single string representation of the object.
2. No you won't be getting a message back for background message.Nep
07/05/2024, 7:11 PMNep
07/05/2024, 7:58 PMShubham Bajaj
07/06/2024, 8:28 PMNep
07/07/2024, 6:26 PM