Timer java script

hello…I’m building an iot project and programming in java script. I would like to run a relay and after 10 seconds it automatically turns off how to do this in java script.

const admin = require('firebase-admin');
admin.initializeApp({
  credential: admin.credential.applicationDefault(),
  databaseURL: 'ws://PROJETOFB.firebaseio.com/',
  projectId: "PROJETOFB",
});

process.env.DEBUG = 'dialogflow:debug';


exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {   
  //Instanciando Webhook
  const agent = new WebhookClient({ request, response });  
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
    function handleDevice(agent) {
      const get = agent.parameters.get;
      const device = agent.parameters.device;
      const status = agent.parameters.status;
        if(device && status){     
            var newStatus;      
            if(status == 'on')
              newStatus="on";
            else  
              newStatus="off";            
            admin.database().ref('automation/'+device).set(newStatus);
            agent.add(``);
        }

Hi @WKS!

Welcome to the forum!

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).