Node Telegraf callback button - javascript

For what we need to pass data to callback button in in simple keyboard (not inline), if thats doesn’t matter?
Example:
const mainMenuKeyboard = Markup.InlineKeyboard([
Markup.callbackButton('Add', 'addAction),
]).resize().extra();
Now, If I want to catch "addAddress" action, I can just do this:
bot.action('addAction',(ctx) => <WHATEVER>);
Everything works just fine&
But, when I want to use simple keyboard (not inline) in my project I cant catch this action using "bot.action("addAction")" I have to use "bot.hears("Add")" :
const mainMenuKeyboard = Markup.keyboard([
Markup.callbackButton('Add', 'addAction),
]).resize().extra();
Don’t work
bot.action('addAction',(ctx) => <WHATEVER>);
Work
bot.hears('Add',(ctx) => <WHATEVER>);

You shouldn't be using Markup.callbackButton (which is InlineKeyboardButton on the Bot API) inside Markup.keyboard(ReplyKeyboardMarkup).
According to Telegram Bot API docs, Markup.keyboard(ReplyKeyboardMarkup) should contain Array of Arrays (not just an array BTW, fix that as well) of KeyboardButton. And Markup.callbackButton(which is Inlinekeyboardbutton on the API) should be used for InlineKeyboard (not reply keyboard).
For more examples on how to use these on telegraf, check this example out

Related

How to isolate a Gunjs database?

I've been trying out GunJs for a couple of days now and I'm really enjoying it. As a starter project I've followed the Fireship chat dapp video aimed at building your own chat.
Here's the issue, now that I've finished the tutorial I would like to create my own chat. However, for some reason if I get a 'chat' node within my own app it seems to pick up on the same 'chat' node as the tutorial one that is online.
onMount(() => {
// Get Messages in large chat
db.get('chat')
.map()
.once(async (data, id) => {
if (data) {
// key for E2E - to do: change for web3
const key = '#foo';
var message = {
//transform the data
who: await db.user(data).get('alias'),
what: (await SEA.decrypt(data.what, key)) + '',
when: GUN.state.is(data, 'what'),
};
if (message.what) {
messages = [...messages.slice(-100), message]
}
}
})
})
This is also the case if I change the encryption key (then the messages just become undefined). Multiple questions arise from this:
Are graph node names unique within the whole of GunDb?
How do you handle conflicts where two gun-based apps call on the same node name?
Is this problem generally solved through filtering using 'header' props?
How do I make it pick up on only my data?
Even if I've read most of the docs, there seems to be something I'm missing in my comprehension of how the graph is generally seperated between apps. Any insight on how this works would be much appreciated.
Are graph node names unique within the whole of GunDb?
Yes.
How do you handle conflicts where two gun-based apps call on the same node name?
You don't. The expected result will be, they will overwrite each other.
Is this problem generally solved through filtering using 'header' props?
I don't think it's the right way to do it.
How do I make it pick up on only my data?
Use your own relay server.
Conclusion :
gunDB doesn't really care about the who fetch / put the data. If you want to protect your data, use your own relay server (not a public one), and put data in your user space. user space is readonly to the public, but read/write for the owner.

How can I call the options of a SubCommand using discord.js? (v13)

I've recently been working on a Discord bot using discord.js's lastest verison, v13, and slash commands. After reading through the documentation on GitHub, I was able to get a subcommand working in my bot:
However, when trying to get the options array from the arguments, I do not know how I can get arguments after getting the SubCommand. To my disappointment, the only function I found was .getSubcommand(), which returns a string oddly enough. I was hoping it would return on object so I can get the options array from it.
How can I get the options object that's within a subcommand? Does this even exist? How can I use the string that is returned?
Thanks!
SubCommands are just subject to the slash command itself you may access the arguments of options provided within it like so:
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'settings') {
if (interaction.options.getSubcommand() === 'moderation_logs') {
const user = interaction.options.getChannel('logging_channel');
}
}
});
Treat them as normal message commands with args but better since all args correspond to the options provided even if they are different sub commands since they fall under the same interaction ( slash command ). Slash commands are awesome 😇!

matrix-js-sdk setup and configuration

I am having some issues trying to connect to a matrix server using the matrix-js-sdk in a react app.
I have provided a simple code example below, and made sure that credentials are valid (login works) and that the environment variable containing the URL for the matrix client is set. I have signed into element in a browser and created two rooms for testing purposes, and was expecting these two rooms would be returned from matrixClient.getRooms(). However, this simply returns an empty array. With some further testing it seems like the asynchronous functions provided for fetching room, member and group ID's only, works as expected.
According to https://matrix.org/docs/guides/usage-of-the-matrix-js-sd these should be valid steps for setting up the matrix-js-sdk, however the sync is never executed either.
const matrixClient = sdk.createClient(
process.env.REACT_APP_MATRIX_CLIENT_URL!
);
await matrixClient.long("m.login.password", credentials);
matrixClient.once('sync', () => {
debugger; // Never hit
}
for (const room of matrixClient.getRooms()) {
debugger; // Never hit
}
I did manage to use the roomId's returned from await matrixClient.roomInitialSync(roomId, limit, callback), however this lead me to another issue where I can't figure out how to decrypt messages, as the events containing the messages sent in the room seems to be of type 'm.room.encrypted' instead of 'm.room.message'.
Does anyone have any good examples of working implementations for the matrix-js-sdk, or any other good resources for properly understanding how to put this all together? I need to be able to load rooms, persons, messages etc. and display these respectively in a ReactJS application.
It turns out I simply forgot to run startClient on the matrix client, resulting in it not fetching any data.

Fetch node issue

This code is using to bring BNB price, I want to push the price into an array. I tried Fetch in HTML page, and it worked perfect.
Node doesn't have fetch as the browser's JavaScript does.
You can try to use the Node's http module directly or use some package like axios.
UPDATE:
However, regarding your particular case - it seems you don't have do make requests manually. You're using node-binance-api package that does requests under the hood. So just remove the code that invokes fetch at all.
ANOTHER UPDATE:
So finally to add a price to the array you can rewrite your function fetchCoinPrice like this:
function fetchCoinPrice() {
binance.prices(function(error, ticker) {
console.log("Price of BNB: ", ticker.BNBBTC);
array.push(ticker.BNBBTC);
});
}

How do I post a tweet using javascript, twitter api and node.js?

Ok...I'm new to this >.<
I have my npm from github.com (node-twitterbot...whose dependency is twit)
I've looked at the twitter api..
What I'm trying to do is add an action which is post a tweet.
I can't seem to find out how to define the string for the actionName (which might be...)
var tweet = ("https://api.twitter.com/1.1/statuses/update.json");
and the actionFunction. Then I need to put it all together to post. Also, I have my instructions written below, however I'm not sure how to apply them. My actionName could be "tweet"? I have no idea how to define my actionFunction either...Can someone explain this? I NEED TO KNOW WHAT TO PUT WHERE. I have the twitterbot.js file open and ready to edit along with with all my oauth keys...access and consumer stuff. Please help anyway you can. I can paste my twitterbot.js file if that helps. Below are the instructions on the npm site reads:
Actions
In order to get your node-twitterbot to actually do something, you need to define actions. It is done through the addAction() method. It takes 2 parameters:
actionName: a string value for the name of an action
actionFunction: a function to be called when a given action is scheduled. (See below for method signature)
So our addAction method might look like this:
Bot.addAction("tweet", function(twitter, action, tweet) {
Bot.tweet("I'm posting a tweet!");
});
The twitter variable passed into the function is the Twit object associated with a given node-twitterbot, and can be managed directly. The same Twit object is available as [TwitterBot].twitter as well.
The action variable passed into the function is the TwitterBotAction created by addAction.
And the tweet object is the tweet passed into the action (if there was one)
TwitterBotActions
addAction() returns a TwitterBotAction object.
var tweetAction = Bot.addAction("tweet", function(twitter, action, tweet) {
Bot.tweet("I'm posting a tweet!");
});
But you will rarely need to directly hold onto the tweetAction directly. You can always get a reference to the action by calling
Bot.actionWithName("tweet");
Which will return the TwitterBotAction object, or null if the name is invalid (or the action already removed)
Again, I'm trying to put all of this together so i can post a tweet using the javascript in node.js Thank you for your time and consideration.

Categories

Resources