async function sendResponse()

in sample-code/javascript/index.js [91:116]


async function sendResponse(reactionType, machineId, data) {

  console.log('Target Project ID:', PROJECT_ID);
  console.log('Topic ID:', TOPIC_ID);

  const message = {
    data: Buffer.from(JSON.stringify(data)),
    attributes: {
      PinballReactionType: reactionType,
      MachineId: machineId
    }
  };

  console.log('Message Data:', message);

  const topicPath = `projects/${PROJECT_ID}/topics/${TOPIC_ID}`;


  try {
    const messageId = await pubSubClient.topic(topicPath).publishMessage(message);
    console.log(`Message ${messageId} published successfully.`);
  } catch (error) {
    console.error(`Error publishing message: ${error.message}`);

  }
}