Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
Can you specify the "scope" of a keyword in botkit, so the keyword can show something different after a specific thread?

The bot I'm trying to build has a question structure as such:

Would you like to learn about the news, or the weather?

-The weather

For which city would you like to check?

-New york

The aim is for the specified keyword New York, the bot answers with the specific weather url. If you answer "news" and then "new york", it would answer the url that is about news in new york. There are a lot of alternative choices in the bot, so it is difficult to find a solution to seperate the keywords with the same name.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I got you a simple example you can work with.

First we define some kind of structure to hold every answer tree and it's leaves. This is a meaningful format of the context you may use:

{
  q: "question",
  a: {
    "answer1": {
      q: "question2",
      a: {
        "answer1": {
          ...
        },
        "answer2": {
          ...
        }
      }
    },
    "answer2": {
      q: "question2",
      a: ...
    }
  }
}

Here you got some code to make the main logic of the simple bot logic even clearer:

const ctx = {q:"Would you like to know about weather or news?",a:{weather:{q:"For which city do you want ot know the current weather? (london or berlin)",a:{london:{q:"Blablbla weather... London!"},berlin:{q:"Blablabla weather... Berlin!"}}},news:{q:"For which city do you want ot know the current news? (london or berlin)",a:{london:{q:"Blablbla news... London!"},berlin:{q:"Blablabla news... Berlin!"}}}}};

// create button with text and callback arguments
const createButton = (txt, cb) => {
  const b = document.createElement("button");
  b.innerText = txt;
  b.onclick = () => {
    [...document.body.querySelectorAll("button")].forEach(e => e.remove());
    cb(txt.toLowerCase())
  }
  document.body.appendChild(b);
}


// your main loop
const bot = (ctx) => {
  alert(ctx.q); // display / alert question
  const cb = (a) => (ctx = ctx.a[a], bot(ctx)); // callback goes to next inner context
  ctx.a && Object.keys(ctx.a).forEach(e => createButton(e, cb)); // create buttons
}

// startup call
bot(ctx);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda