I am building a Chat Bot with Dialogflow and Telegram - Python Flask web hook.
I am having trouble starting the conversation.
When I type '/Start', with a capital 'S' then is works. When I type '/start' with a lowercase 's', then it fails with the fall back intent.
I deleted the default welcome intent.
How do I start the conversion with the lowercase '/start' as well as the uppercase start '/Start'.
Thanks
According to documentation there are two events that you have to add to your intent: TELEGRAM_HELP for /help and TELEGRAM_WELCOME for /start.
I have just tried this and it works in my bot.
Related
I have a telegram bot and I use the python-telegram-bot library. what I try to is when user for example press on trade button I want to ask him about some deatails so I have to wait for the user input then process the answer
I have this this CmmandHandler which working well but its work just with command
ConversationHandler(
entry_points=[commandhandler('trade',trade)],
states={
NAME_adduser: [MessageHandler(Filters.text, callback=binance)],
},
fallbacks=[CommandHandler('quit', quit)]
)
I search alot but found nothing about use InlineKeyboardButton value as a command
I need some help/suggestion to prevent a discord bot from executing a command in a user prompt.
My bot currently has a feature that prompts the user a question, and it'll add whatever the user's answer is to the database. The problem that I'm trying to solve is, currently the user's able to enter a bot command as an answer, and the bot would both execute that command and take that as an answer to add to the database.
A very quick example to show how problematic this can get:
User: ?question
Bot: Cats or Dogs?
User: ?question
Bot: "?question" have been added to the database
Bot: Cats or Dogs?
I don't have a problem with the bot adding the command to the database, because that's what the user entered (it might be relevant for the user to enter a bot command there), but I don't want the bot to execute that command.
Right now I have 2 vague ideas to solve this (I don't know whether or not any of this will be valid):
I need to turn the user's answer into an "answer" type variable where the bot can't use it to search for commands, but can still use it to upload to the database and fetch from it and display in a list of answers. Although I don't know if this can be executed before the bot starts to search for the command.
I need to somehow change how this system of question & answer works.
Note: Currently my bot detects a command by slicing the first bit of the user's message .slice(config.prefix.length)
Any help or suggestion will be much appreciated.
Thanks in advance!
Here's some answers to your question:
The bot takes in a command as an answer.
If you ever change your mind, you can disallow this by simply allowing only a few selected responses ("cat" or "dog") or disallowing commands that start with a ?.
The command is executed if a command was used as an answer.
This is because you check if the message is a command down the line, somewhere in your code. Not only does the bot recognize the user's message as a valid answer, but it also recognizes that it fulfills the prefix you set and thus it runs the command.If you have a flag that indicates that the user's next response is an answer to the Q&A question, then you can check if that flag is active before executing the command. For example:
// Assume that the user's ID is in this array after they
// requested to answer a Q&A question.
var usersAwaitingResponse = [];
...
client.on("message", function(message) {
if (usersAwaitingResponse.includes(message.author.id)) {
// take in the answer and then end the function by calling "return;"
} else {
// check if the message was a command and act accordingly
}
});
Prefix Checking
Lastly, I recommend that you check if a message is a command by using .startsWith(config.prefix) on the message text. If you want the user to only input allowed characters after the prefix, then you can use a regular expression. Either method saves time and memory rather than slicing the string. An example of those can be seen below:
// using "startsWith"
function checkIfCommand(message) {
return message.content.startsWith(config.prefix);
}
// using a regular expression
function checkIfCommand(message) {
/**
* If all the matches are fulfilled, the test passes:
*
* ^ - The match should be at the beginning of the string.
* ${config.prefix} - The prefix (interpolated into the string).
* [A-Z0-9]+ - match as much characters that are A to Z or 0 to 9
* \s? - Match a whitespace character (if there is one)
* "gi" - global, case insensitive
**/
return new RegExp(`^${config.prefix}[A-Z]+\s?`, "gi").test(message.content);
}
I got a weird problem with dialogflow / node.js backend.
Within Dialogflow I have two entities "color" and "order_amount". I set the entities to required within the intent. But only one of the required entities is send back to my backend and the other is undefined. Though both are received within dialogflow.
app.intent('Default Welcome Intent - yes', (conv, {product_color}, {order_amount}) => {
console.log({product_color});
console.log({order_amount});
conv.ask(`Top. In welke maat?`);
});
So for example, when this intent runs the slotfilling is being done in dialogflow. But I only the first entity is defined e.g {color} and {order_amount} is undefined. When I switch {product_color} and {order_amount} as the below example. Then product_color is undefined.
app.intent('Default Welcome Intent - yes', (conv, {order_amount}, {product_color})
Anyone knows whats going on?
Got the answer myself. You can use "params": https://actions-on-google.github.io/actions-on-google-nodejs/classes/dialogflow.dialogflowconversation.html#parameters
The issue is that you're mangling your JavaScript. The second function parameter contains an object with all the Intent parameters. The {name1} syntax in JavaScript maps object attribute names to a variable. So you could rewrite the line as
app.intent('Default Welcome Intent - yes', (conv, {product_color,order_amount})
Yesterday I started coding a bot using the guide from discord.js. The core is just with what you finish the Command Handler part with.
I was working on a voting command, where the bot would react with Unicode symbols like :one: :two: :three:.
This is where I encounter my problem. Using:
module.exports = {
name: 'testing',
description: 'creates a reaction',
aliases: ['test'],
cooldown: 1,
execute(message, args) {
if (!args.length) {
message.react(':one:');
}
}
};
Gives me a DiscordAPIError: Unknown Emoji
I spend some time trying different emotes like 🔥 and they are working as expected. Using the emote ID (422515569623957504) does not work as well for me.
Is this a mistake on my side or a bug?
In Discord.js to react a message with a emoji you need to write the emoji (with 🔥 or 😀, full list here) or with a Emoji.
To react with numbers you can use this:
0⃣ 1⃣ 2⃣ 3⃣ 4⃣ 5⃣ 6⃣ 7⃣ 8⃣ 9⃣ 🔟
Just copy the number you need and you're all set.
To react a message with a custom emoji, you need to do something like this:
message.react(message.guild.emojis.get('123456789012345678'))
.then(console.log)
.catch(console.error);
Note: Bots can use emojis from all servers (like Nitro). client.emojis returns a Collection of all emojis the bot can use, client.emojis.get('id') to get the emoji from another server.
API.ai's prebuild packages allow you to easily get long lists of intents. Currently I'm trying to make use of their smalltalk package, which has at about 100 intents, and response to each.
I am making use of the api-ai-recognizer package to listen for intents. That works well, but now I have to match those intents, so that I can define the dialog (which is nothing more than using the fulfillment). And this is where I am having trouble.
intents = IntentDialog({recognizers: [apiairecognizer(CLIENT_TOKEN)]})
intents.matches('smalltalk', smalltalk_handler) // No luck
intents.matches(/smalltalk/, smalltalk_handler) // No luck
intents.onDefault(default_handler)
In the default_handler I capture the args:
{"score":1,
"intent":"smalltalk.greetings.how_are_you",
"entities": [
{
"entity":"Lovely, thanks.",
"type":"fulfillment",
"startIndex":-1,
"endIndex":-1,
"score":1
},
{
"entity":false,
"type":"actionIncomplete",
"startIndex":-1,
"endIndex":-1,
"score":1
}
]}
This makes sense according to the documentation of how matches works.
But that does mean that I don't know how to actually use the full list of intents, without explicitly copying every single intent in.
Just to clarify, if I use the exact intent:
intents.matches('smalltalk.greetings.how_are_you', smalltalk_handler)
I receive the nice response: Lovely, thanks.
Any suggestions?
So far, the only thing I have come up with is to modify the api-ai-recognizer such that it will return only smalltalk as intent, whenever it encounters a version of it. This way the intent dialog only needs to recognize one intent. Because they are handled in the same way, it doesn't matter at this point.