Untitled

mail@pastecode.io avatar
unknown
javascript
a month ago
1.3 kB
5
Indexable
Never
fastify.post('/generatetalk', async (req, reply) => {

  console.log("value of req.body: ", JSON.stringify(req.body))
  const { script, clientId } = req.body;
  console.log(`\n\nReceived /generatetalk request - Script: ${JSON.stringify(script)}, ClientId: ${clientId}`);

  if (script && clientId) {
    try {
      socketMsg(clientId, JSON.stringify({ loading: `Sending request to Avatar service...`, bigText: "Avatar Talk Generation", progress: 48, colo
r: "00FF00" }))
      const response = await generateTalk(script, clientId);
      if (response.error) {
        console.log('\n\nError generating talk:', response.error);
        reply.status(500).send({ error: response.error });
      } else {
        socketMsg(clientId, JSON.stringify({ loading: `Letting client know that Avatar service was contacted...`, bigText: "Avatar Talk Processin
g and Response", progress: 52, color: "#00FF33" }))
        reply.send(response);
      }
    } catch (error) {
      console.log('\n\nFailed to generate talk:', error);
      reply.status(500).send({ error: 'Failed to generate talk' });
    }
  } else {
    console.log('\n\nMissing text or clientId in /generatetalk request');
    reply.status(400).send({ error: 'Missing text or clientId' });
  }
});
Leave a Comment