Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Why does botkit keep repeating itself in Slack? #42

Open
Mattw11486 opened this issue Feb 2, 2023 · 0 comments
Open

Why does botkit keep repeating itself in Slack? #42

Mattw11486 opened this issue Feb 2, 2023 · 0 comments

Comments

@Mattw11486
Copy link

Mattw11486 commented Feb 2, 2023

The issue is with controller.hears('keyword', 'message')
If its being used with the message and the bot responds with that keyword it keeps replying back to it's own message.
For example, if the bot's reply is bot.reply(message, 'keyword);
then it will just keep repeating keyword over and over
The only workarounds I have found for this is to either:

  1. user 'direct_message, mention, direct_mention'
  2. use reply messages that don't contain the keywords

The problem with method 1 is that I can't use a common.js file to work for both Teams/Slack/Discord, I have to create separate .js files for each channel to do the same exact things.

Method 2 will work but I am worried that if it responds to another message (like a random message from my ChatGPT integration) that does contain a keyword for some other controller.hears message it will cause an issue of it responding unnecessarily.

I am thinking the only thing to do is to have it listen for it's own bot identity or app ID and then return if it sees itself but I am not really sure how to find the Bot ID. If its the App ID in api.slack that did not work for me.

image
.

`	//Stock Quotes
	controller.hears('stock price', 'message,direct_message,direct_mention,mention', async function(bot, message) {
		const stock = message.text.match(/stock price of (\w+)/i)[1];;
		const url = `https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=${stock}&apikey=${process.env.STOCKAPI}`;
		try {
			const body = await rp({ uri: url, json: true });
			if (body["Error Message"]){
				bot.reply(message, 'Invalid stock symbol');
				return;
			}
			const stockPrice = body["Global Quote"]["05. price"];
			const roundedStockPrice = Math.round(stockPrice * 100) / 100;
			bot.reply(message, `The latest stock price of ${stock} is $${roundedStockPrice}`);
			return;
		} catch (err) {
			console.log(err);
			bot.reply(message, 'Sorry, I was unable to retrieve the stock price.');
		}
	});`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant