How to remove the embed from specific messages and from messages coming from specific users/bots using Discord.js - node.js

I'm trying to code a bot that is able to remove the embed of specific messages or the embed created from the links posted by specific users and bots present in the server.
For example, let's say I don't want to see the twitter embed when someone posts a tweet: my bot would automatically remove the twitter embed.
Other case, I don't want people to see the embed of the messages posted by another user or bot present in the server, my bot would then automatically remove the said embeds.
However, reading the API documentation, I didn't see any possibility to do so. Maybe I missed it or maybe there's a trick to do so. Or maybe it's not supported by the API yet.
So does anyone know how I could achieve that goal please?
PS: Yes, I know I could simply deactivate embeds in the server settings, but that's not the goal I want to achieve here. I want it to be specific to certains links/messages and users/bots.
Thanks

You can use the suppressEmbeds method of message.
client.on("message", message => {
if (message.author.bot) return false;
if (message.author.id !== "YourID") { // Example Condition
message.suppressEmbeds(true) // Removes all embeds from the message.
}
})

Related

Can I send Hero cards to whats app by using Twilio

I have chat bot, I build it with bot framework nodejs SDK I integrate this chat bot to whatsapp and I want to display some buttons in the whatsapp chat,
So is there any one found a solution for this problem pleas help me
Note: I try to send a hero card but I run to problem
Error: TwilioWhatsAppAdapter.parseActivity():
An activity text or attachment with contentUrl must be specified.
I don't know how bot framework attempts to send WhatsApp messages with buttons, but I doubt it fits with the way Twilio wants to send them.
Currently, to send a message with buttons, you need to register and use a template message. When you send the text of a message that matches one of your templates, then Twilio will deliver the entire template with buttons as well.
For the future, look out for the Twilio Content API which will streamline templates, buttons and other rich messages across platforms.
It looks like you are using the TwilioWhatsAppAdapter from the botbuilder-community-js repo.
Looking at the adapter's code, it doesn't appear to be configured to handle any card other than a 'signin' card (see here). If you don't mind doing a little leg work on this, I don't see why you couldn't fork this repo and build in functionality that supports a hero card similar to the signin implementation.
I imagine it would look something like this:
case 'application/vnd.microsoft.card.hero':
// eslint-disable-next-line no-case-declarations
const hero = attachment.content;
message.body = `${ hero.text }\n\n`;
message.body += (hero.buttons[0].title ? `*${ hero.buttons[0].title }*\n` : '');
message.body += hero.buttons[0].value;
break;
The above may need a little massaging but it wouldn't be far off from this. Then, you just need to build the library for use.

How do I make a Discord bot using discord.py rewrite that can make bot users that are not real

I have seen a few bots that have made a bot user
one bot called BetterCensoring did that
It looked like this
does anyone know how to make that?
I have tried to search for an answer a lot but I couldn't find any answers.
Stuff like this is not achieved by actually creating a new user account but rather using a webhook. The send method has the ability to customize username and profile picture of the message.
Webhooks are most easily created with await channel.create_webhook()
Note that a guild can only have 10 webhooks at a time, which is why most bots that use this functionality create a webhook, send a message with it and then delete it right afterwards.
Example (recreating your creeper censoring):
async def on_message(message):
if message.content.startswith('bad word'):
webhook = await message.channel.create_webhook()
await webhook.send('####', username='Creeper', avatar_url='this is an url leading to the creeper image')
await webhook.delete()

Initiate message from bot in dialogflow

I want to get the welcome message from bot first in dialogflow. I am not sure how to do this. Any ideas on how to do this.
I tried reading about events in dialogflow as Default welcome intent uses "Welcome" event. But not able to find any solution.
As I opened up my bot framework, it should pop up "Hi, I am a virtual assistant. How can I help you?"
I am not sure of which bot technology you are using, but if your front end is in html/js, you may call a function like this:
Define it something like:
function myFunction(){
''here you may pass a parameter to your bot to display a pre-defined message. I am not going in details here, as I am not sure about the framework you are using.''
}
The onload (in body) will call myFunction(), everytime the page is refreshed.
P.s - I will update this answer once I get more details from your end. Since I am new here, please excuse in case of any issues.

Is it possible to lookup a database in a Dialogflow intent?

I'm trying to make an app using DialogFlow which finds a specific object in a specific place.
This is a generic example.
The user would say something like "Where to I find Dog in Europe" and the app would reply with "Dog can be found in Europe via: breeding, finding it out in the wild or by buying it"
considering Dog as input1 and europe as input2
Ideally the app should be able to cross reference input1 and input2 to find the correct response. Can I implement a database like structure and do this?
You can't access a database from Dialogflow directly, but you can build your own fulfillment backend that can do anything you want. It communicates with Dialogflow via HTTP requests/responses in the Dialogflow Webhook format.
Here is an example fulfillment that reads data from Firebase database - https://github.com/actions-on-google/dialogflow-updates-nodejs
You can't access a database directly in Dialog flow, but you can build your own fulfillment back end. I have been using Airtable as a database and Integromat and Webhooks to query the database and parse the results back to Dialogflow. As a novice coder I found this to be the simnplest way.
KaySubb is right, you can make a fulfillment that reads data from a firebase database(or firestore).
You can do this turning on fulfillment at the bottom page of the intent page.
First go to https://console.firebase.google.com/ (login with google account) and you should be able to see your google cloud platform project.
To use firebase, you need to first install it. Get node.js as you need npm first. I'm not sure what OS you're on but go into command line or terminal and type.
npm install firebase --save
then type:
firebase login
this will authenticate your login and connect your project when you deploy.
Then use go to the directory you want to create your project in:
firebase init functions
Select your project and select javascript, install all dependencies
Now go to functions and open the index.js file. Here you can change you write code needed in js.
Write your functions and type:
firebase deploy
in the command line open in the file directory. When it completes, it will
give you a link. This as the webhook URL in dialogflow (it should start with
https://us-central). If you see only 1 link which says
console.firebase.google.com....... then open that link on a browser, click on
"functions" on the left side of the screen and get the link from there.
This should get you started with firebase, now you can link your project to firebase fulfillment. There is great firestore explanation here
https://www.youtube.com/watch?v=kdk6MhhI8oc
But I'll give you a brief explanation:
On the top of your index.js file you will need:
const functions = require('firebase-functions');
var admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
var firestore = admin.firestore();
The basic code is here:
exports.webhook = functions.https.onRequest((request, response) => {
switch(request.body.result.action){
case 'saveData':
let params = request.body.result.parameters
firestore.collection('colName').doc('docName').add({
name:params.name
age:params.age
}).then(() => {
response.send({
speech:
`this is a response for "${params.name}".`
});
})
.catch((e => {
console.log('Error getting documents', e);
response.send({
speech:
`Sorry, something has gone wrong. Try again and if the problem persists, please report it.`
});
}))
break;
default:
}
})
I'll explain what it does:
You need the switch to decide which intent to do. request.body.result.action returns the action name (write this in dialogflow just above the parameters).
Once that is decided request.body.result.parameters give you the parameters from the intent. params.______ gives you the parameter.
I would definitely recommend reading the official documentation:
https://firebase.google.com/docs/firestore/quickstart
to help understand the data structure to help create the ideal database for you. Essentially a collection is a list and within that a doc is one entry. You can name them yourself of using the entries from param.
respond.send is what the bot will reply to the user, I've also shown how to use the parameters in the response.
.catch will just store any errors in the log, you can read the log in console.firebase.google.com.... open your project and click on function. There will be a place to read logs there. You can check any errors encountered over there.
default: will output whatever default response you wrote on dialogflow at the bottom of the intent.
Hope this helps,comment any questions. I have gone through a huge amount as concisely as I could. This will take some time to get used to and become good at, follow the docs and the youtube videos if you have a lot of trouble!
If you're having even more trouble, there is a slack that helps people that I can direct you to.

Botframework LUIS Slack bot only reply when name is mentioned

I'm creating a bot in slack using Microsoft's botframework and LUIS and in Node.js. Currently my bot will reply every time someone says something in the channel, however I want my bot to only reply when its name is mentioned in my slack channel. i.e. #my-bot do this
How would I approach this? Would I have to add slack api in order to do this?
One way I'm thinking is to create an entity to check for if #my-bot is mentioned, and if it is then reply and if not then don't. However, I feel there are better ways in doing this.
Thanks.
Edit:
dialog.onDefault(function (session) {
var msg = new builder.Message(session).entities();
console.log(msg);
console.log(session);
session.endDialog('Default Dialog');
});
I've looked through both msg and session and the Entities of both are empty.
I was able to use session.message.entities to use mentioned to know whenever the bot was mentioned.

Resources