genetic-orange
genetic-orange15mo ago

How can I set the timetable?

Hello, I wanna set my bot, that if the client is asking the question at 3am, the bot answearing him that the shop is closed
3 Replies
Tico | Voiceflow Assistant
To set up a Telegram bot using Voiceflow and Telegraf, you can follow these steps: 1. Telegram Setup: Add your Telegram token to your .env file in the property BOTTOKEN. 2. Telegraf Setup: Create a bot using the following code lines:
const Telegraf = require('telegraf'); // import telegram lib
const bot = new Telegraf(process.env.BOTTOKEN); // get the token from environment variable
bot.start((ctx) => ctx.reply('Welcome')); // display Welcome text when we start bot
bot.hears('hi', (ctx) => ctx.reply('Hey there')); // listen and handle when user type hi text
bot.launch(); // start
const Telegraf = require('telegraf'); // import telegram lib
const bot = new Telegraf(process.env.BOTTOKEN); // get the token from environment variable
bot.start((ctx) => ctx.reply('Welcome')); // display Welcome text when we start bot
bot.hears('hi', (ctx) => ctx.reply('Hey there')); // listen and handle when user type hi text
bot.launch(); // start
3. Voiceflow Setup: Create a new function that takes Telegraf ctx, userID, and a request in as arguments. Inside the function, make an API call to the Voiceflow /interact endpoint.
async function interact(ctx, chatID, request) {
const response = await axios({
method: 'POST',
url: `https://general-runtime.voiceflow.com/state/user/${chatID}/interact`,
headers: { Authorization: process.env.VOICEFLOWAPIKEY },
data: request
});
}
async function interact(ctx, chatID, request) {
const response = await axios({
method: 'POST',
url: `https://general-runtime.voiceflow.com/state/user/${chatID}/interact`,
headers: { Authorization: process.env.VOICEFLOWAPIKEY },
data: request
});
}
4. Handling User Input: Replace the 'hi' utterance with a regex like .+. This means that the bot will listen for everything. All the text received will be passed directly to Voiceflow.
const ANYWORDREGEX = new RegExp(/.+/i);
bot.hears(ANYWORDREGEX, async (ctx) => {
let chatID = ctx.message.chat.id;
await interact(ctx, chatID, { type: 'text', payload: ctx.message.text });
});
const ANYWORDREGEX = new RegExp(/.+/i);
bot.hears(ANYWORDREGEX, async (ctx) => {
let chatID = ctx.message.chat.id;
await interact(ctx, chatID, { type: 'text', payload: ctx.message.text });
});
For more detailed information, you can refer to the Voiceflow Telegram Integration Guide.
W. Williams (SFT)
You can use a JavaScript step and just set a message. No need for a LLM to do it.
genetic-orange
genetic-orangeOP15mo ago
do you have the code? Cause I have been searching and asking GPT, but I didn't get any result

Did you find this page helpful?