How to catch messageBack in node.js [closed] - node.js

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am trying to use messageBack in Bot framework. (The reason is postBack is not supported for MS Teams and imBack shows the system message to the user. I also tried to use invoke but that function is no longer in the botbuilder library)
I found the function messageBack in the library botbuilder, but I dont know how to catch the action once user presses the button.
For imBack I can use this:
bot.dialog('catchOption', [
function (session, args, next) {
}
]).triggerAction({ matches: /choose-time-card[0-9]+-[0-9]+/i});
I tried invoke but this is said to be limited to "internal use" whatever that means. So I tried this but it doesnt work:
bot.on('invoke', function (event) {
var msg = new builder.Message().address(event.address);
msg.data.text = "I see that you clicked a button.";
bot.send(msg);
bot.send(JSON.stringify(event));
});
Does anyone know?

A few comments on this:
The SDK release from a few days ago 3.14 reinstated the Invoke ActionType.
To accomplish what you want to do it is as simple as something like this:
var bot = new builder.UniversalBot(connector, function(session) {
if(session.message.text === "your messageback value"){
//do stuff
}else{
session.send("You said: %s", session.message.text);
}
}).set('storage', inMemoryStorage);

Related

How do I get a bot to specify the username and tag of the creator in discord.py rewrite? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am not understanding how to mention the creator of the bot despite changing the tag and username.
I am using discord.py rewrite.
Can someone please help me?
Here is the code:
#client.command(aliases=["OWNER", "creator", "CREATOR"])
async def owner(ctx):
I want the code below all that...
You can use youe User ID which always remains constant. Your command would look like this:
#client.command(aliases = ['OWNER', 'creator', 'CREATOR'])
async def owner(ctx):
try:
user = await client.fetch_user(YOUR_ID)
await ctx.send(f'Owner: {user.mention}')
except:
user = 'MyUsername#0000'
await ctx.send(f'Owner: **{user}**')
Where YOUR_ID is your Discord User ID that can be obtained by right-clicking your profile picture from one of your messages on Discord.
Note: You will only be mentioned if you are present in that server, otherwise you'll have to tell it what to send (MyUsername#0000 in this case).
There are several ways of doing that but the important thing to note is that you (Owner of bot) must be present in server in which the command is used to actually get proper mention. Otherwise, It will show something like this:
<#1234567890> (Where 1234567890 is your ID).
You can use this code but again it will only mention you if you are in the server.
#client.command()
async def owner(ctx):
owner = client.get_user(Your ID)
await ctx.send(f"Bot's Owner is {owner.mention}")
IMPORTANT NOTE: You need to have "Members Intents" enabled in order to get the above code running. Please enable them Portal from your applications bot section after that enable intents in your code. Learn more from here
This method isn't recommended since it uses intents and doesn't actually mentions the user.

Random meme generator discord.js, glitch.com, node.js [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am new to discord.js coding, I have been trying to make a meme generator, any can help me?
You can use npm packages to generate memes.
for this command idea, I will use "random-discord"
First of all , install random-discord by using npm i random-discord random-discord Docs
and create new random-discord app with :
const { Random } = require('random-discord')
const random = new Random
finally, Add this code to your bot main file :
client.on('message', message => {
if(message.content.toLowerCase() === "meme") {
let meme = await random.getMeme()
message.channel.send(meme)
}
})

How to get a firebase's database keys and values [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm new to firebase, and I'm doing a database for my discord.js bot. I know how to do almost everything, except i don't know how to get all the db data. Let me explain:
My database structure looks like this:
database structure
And i would like that when executing the showconfig command, it shows something like this:
announcementsChannel: "news",
autoRole: "false",
autoRoleName: "none",
// etc...
Is there any way to get every key and its value, and putting it all inside a message?
db.collection("users").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(`${doc.id} => ${doc.data()}`);
});
});
You can read the docs online at this link : https://firebase.google.com/docs/firestore/quickstart

How promises work in Typescript - I have error in mysql [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm working in an Angular 8.3 app with Node 10.17 and Mysql.
When I try to send information in JSON to the Backend I got an error in promises and I don't know what to do.
I've already investigated and I can't find the error
My code
In Angular Component.TS
async entrar(): Promise<void>
{
const datosJSON = JSON.stringify(
{
NombreP: "Fulanito",
ApellidoPa: "Perengano",
ApellidoMa: "merengano",
Calle: "ejemplo",
Numero: "9235",
Colonia: "ejemplo",
Municipio: "ejemplo",
CP: new Number(1234),
NumSeg: "595625634",
FechaNacimiento: "1234-56-78"
}
);
console.log(datosJSON)
await this.http.post('http://localhost:3000/alumnos/persona', datosJSON ).subscribe((data) =>{
this.datos= data;
console.log(this.datos);
})
}
Welcome to StackOVerflow!
The more details you give, the more accurate the answers you get.
I'm seeing a lot of misconceptions here:
You should not JSON.stringify your object, because then you'll be converting your object into a string. Usually in the POST request you just send the object as it is or in some other scenarios you can create a FormData
Observables are not Promises
You are not returning anything and certainly not a Promise.
Don't subscribe on your Service, if you really really need a promise here, consider:
return this.http.post('http://localhost:3000/alumnos/persona', datosJSON).toPromise()
Probably you don't need async/await here
this.datos = await this.http.post('http://localhost:3000/alumnos/persona', datosJSON ).toPromise();
In your case the data variable inside the subscribe method is returned when the observable is converted to Promise and awaited

beginner node.js callback example [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm pretty novice in nodejs
This is a very easy php example that I want to write in nodejs
$key='foo';
$inside= openthedoor($key);
if(!$inside){ //wrong key
$key= getanewkey();//get a new key
$inside= openthedoor($key);//open the door again
}
How can I do this callback in nodejs?
appologies for the stupid question.
Keep in mind that you can still write things synchronously in Node.js, but if openthedoor() did happen to require a callback function, this is what it'd look like:
var key = 'foo';
openthedoor(key, function(inside) {
if (!inside) {
key = getanewkey();
openthedoor(key, function(inside) {
// check if we're inside again
});
}
});
A callback function is a function that is called on completion of another function. In the example, you are passing this function:
var callback = function(inside) {
if (!inside) {
// do something else
}
});
Into this function to be called when there is a result:
openthedoor(key, callback);

Resources