Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda