Undefined team_id in BoltJs event - node.js

I'm trying to handle the situation when my Slack app (built on top of BoltJS) is removed from a workspace, in order to remove its record from the database.
Here is the section that handles it:
app.event('app_uninstalled', async({team_id}) => {
await db.removeTeam(team_id);
await http.delete(`${constants.BASE_URL}?teamId=${team_id}`);
});
However, the team_id value that is supposed to come from Slack is undefined. I also checked the Slack docs and it seems I should be looking at the team_id parameter, which I do.
I would appreciate any help to see what I'm doing wrong :)

Ok, I found the solution. The team_id parameter should be accessed from the body object, therefore:
app.event('app_uninstalled', async({body}) => {
await db.removeTeam(body.team_id);
await http.delete(`${constants.BASE_URL}?teamId=${body.team_id}`);
});

Related

TypeError: Cannot read property 'topic' of undefined discord.js

iam trying to get the name and topic of a channel
can anyone tell me what did i do wrong
const rules = bot.channels.cache.get('776828354400747580');
console.log(`${rules} :- ${rules.topic}`)
you should use the code once your bot is ready:
bot.on('ready', () => {
const rules = bot.channels.cache.get('776828354400747580');
console.log(`${rules} :- ${rules.topic}`)
});
So the channel is cached and you can access it
It seems like the program is trying to access the 'topic' property of the channel when it's undefined. Are you sure you have the right channel id? It's possible that either the channel id you entered is wrong, or the channel isn't a text channel. As another user suggested, it's also possible that you didn't have the code in the
"on-ready" event.
bot.on('ready', () => {
// Code here
});

How to get impression from google ads using google-ads-node( met one issue; INVALID CUSTOMER ID even though it is set correctly.)

Hope you are safe and good for this pandemic time.
I am developing some functional to fetch data from google ads using google-ads-node.
But for now I met one issue.
Error: 3 INVALID_ARGUMENT: Invalid customer ID '... .... ...'.
However it is set correctly on ads account.
Please understand me messy picture.
The code I used like this.
const auth = await authenticateGoogle(`keys/${process.env.GOOGLE_YT3_API_CREDENTIAL_PATH}`, 'installed');
const client = new GoogleAdsClient({
access_token: auth.credentials.access_token,
developer_token: process.env.DEV_TOKEN,
parseResults: true,
});
const service = client.getService("GoogleAdsService", { useStreaming: true });
const request = new SearchGoogleAdsStreamRequest();
request.setQuery(`
SELECT
campaign.resource_name,
metrics.impressions,
segments.date
FROM
campaign
WHERE
segments.date BETWEEN "2019-01-01" AND "2020-01-01"
`);
request.setCustomerId(process.env.CUSTOMER_ID);
const call = service.searchStream(request);
const chunks = [];
call.on("error", err => reject(err));
call.on("data", (chunk) => chunks.push(chunk));
call.on("end", () => resolve(chunks));
Would you help me how I can figure out this issue please?
Thank you.
The only thing you need is to pass the CustomerID without dash (-). More specifically, you just need passing the CustomerID with XXXXXXXXXX format instead of XXX-XXX-XXXX.
google-ads-api need client_id and login_customer_id.
i think CUSTOMER_ID need to change as "client_customer_Id" not a "login_customer_id"
For the ones that ended up here in 2021+.. the "google-ads-node" does not recieve any more support from Opteo, they now support the "google-ads-api" lib that themselves made.

how do I write to firebase outside of a Firestore trigger?

I'm trying to write to firestore from an http post trigger, however my doc.data() keeps coming back as undefined, even though it clearly exists. (see screenshots). I did find somewhere that MIGHT have the answer I'm looking for but they want $50 for the POSSIBILITY fo an answer lol.
const admin = require('firebase-admin');
admin.initializeApp({CREDENTIALS});
const db = admin.firestore();
export const helloWorld = functions.https.onRequest(
(request, response) => {
var ref = db.collection('Messages').doc("18438557133");
ref.get().then((doc: any) => {
console.log(doc);
console.log(doc.data());
console.log(doc.exists);
response.end()
});
})
this is the link i found that might be helpful:
https://angularfirebase.com/lessons/dialogflow-with-firebase-cloud-functions/
what am I missing?
The output is suggesting that the document doesn't actually exist. Notice that doc.exists is false, and the documentation for doc.data() says that it will return undefined if the document doesn't exist.
The Firestore SDKs aren't wrong about this sort of thing. You might be looking at a different document than the one you think you're getting. Or you might be looking at a different project than the one where the function is deployed. In any event, you're going to have to take a close look at your deployment to make sure everything is as you expect.

awaitMessages inside async function discord.js

I am fairly new to async and I am trying to get the response from a user to a bot via a private message. I have done this before in sync, but not async. I have working code that properly awaits reactions that I worked into the following code, but it doesn't seem to work the same way (obviously) as I am getting (node:10080) UnhandledPromiseRejectionWarning: TypeError: msg.awaitMessages is not a function as an error when I run it.
I've looked around in trying to find awaitMessages to work for a private message inside an async function but it looks to be more complicated than putting something like the answer to this question Await reply in private message discord.js
async function cardExists() {
let matchedcards = []
let msg = await message.author.send(`Please provide the cardnames that you would like to add to '${userdeckname}'.\n\n**NOTE:** Please separate each card with a comma and space, like so "Pact of Darkness, Aquos Slam, Karmic Balance"`)
const filter = m => m.author.id === message.author.id
const reply = await msg.awaitMessages(filter, { max: 1 })
.catch(console.error);
let cardsToAdd = reply.first()
let usercardnamearray = cardsToAdd.content.split(", ")
I simply want the question to be asked, and await the user to reply in a private message to the discord bot. Some code that runs after the snippet above (once cardsToAdd is declared) ends up checking if each card in the list exists in a mysql database and pushes the cards that succeed to an array to be used later and sends the cards that fail to the private chat.
Thanks for your help in advance!
Use msg.channel.awaitMessages instead of msg.awaitMessages according to the official documentation.

Return Stripe Response within Firebase Function to Swift Application

I’m trying to make an iOS that connects to Stripe and can show user information and data and things.
I’m doing this by using Firebase Functions, so I don’t have to maintain a server, and also because I’m a newb to the extreme.
But when I try to say, get a customer by using the Firebase callable functions, ex.
exports.getCustomer = functions.callableFunctions((data, context) => {
stripe.customers.retrieve(
data.customerID, function (err, customer) {
console.log(‘customer’)
});
});
I’m not sure where to place the “return” in order to actually use that ‘customer’ object in my app. I tried to stick a “return customer” under the console.log, but it’s never....... returning. I’ve also tried creating an empty string variable that I set after the console log and return, but that is always coming up as an empty string on the app.
Sorry for the typesetting issues, and this question is very theoretical - I’m typing on my phone because I don’t want to forget it and I’ll be away from my computer for a while.
Can anyone provide any guidance on how I’d return the ‘customer’ object to my iOS app?
As detailed here, since the release of the Stripe node.js API version 2, they added support for promises: "Every resource method now returns a Promises/A+ compliant promise in addition to supporting the conventional callback".
So you could do as follows:
exports.getCustomer = functions.callableFunctions((data, context) => {
const stripeCustomerID = data.customerID;
return stripe.customers.retrieve(stripeCustomerID)
.then(customer => {
return { customer: customer };
})
.catch(err => {
throw new functions.https.HttpsError('<status error code>', 'xxxxxxx');
});
});
As indicated in the doc, have a look here for the possible values of

Resources