Related
I am trying to save data from tweets to a mongoDB database using node and express.
I am using the twitter api to stream twitter data with a specific hashtags. I just want to save the text content of the post:
Here is how the tweet content shows up when it is console.logged:
(Note this feature works and this is my own posted
{
created_at: 'Tue Mar 15 06:38:58 +0000 2022',
id: 1503621761388134400,
id_str: '1503621761388134410',
text: '#TelecomDisaster Test for project 2',
source: 'Twitter Web App',
truncated: false,
in_reply_to_status_id: null,
in_reply_to_status_id_str: null,
in_reply_to_user_id: null,
in_reply_to_user_id_str: null,
in_reply_to_screen_name: null,
user: {
id: 1472188612494172200,
id_str: '1472188612494172172',
name: 'Dillon Rampersad',
screen_name: 'R_Dillon_25',
location: null,
url: null,
description: null,
translator_type: 'none',
protected: false,
verified: false,
followers_count: 5,
friends_count: 11,
listed_count: 0,
favourites_count: 22,
statuses_count: 63,
created_at: 'Sat Dec 18 12:55:26 +0000 2021',
utc_offset: null,
time_zone: null,
geo_enabled: false,
lang: null,
contributors_enabled: false,
is_translator: false,
profile_background_color: 'F5F8FA',
profile_background_image_url: '',
profile_background_image_url_https: '',
profile_background_tile: false,
profile_link_color: '1DA1F2',
profile_sidebar_border_color: 'C0DEED',
profile_sidebar_fill_color: 'DDEEF6',
profile_text_color: '333333',
profile_use_background_image: true,
profile_image_url: 'http://pbs.twimg.com/profile_images/1472188757956780033/OMlZZeZI_normal.jpg',
profile_image_url_https: 'https://pbs.twimg.com/profile_images/1472188757956780033/OMlZZeZI_normal.jpg',
default_profile: true,
default_profile_image: false,
following: null,
follow_request_sent: null,
notifications: null,
withheld_in_countries: []
},
geo: null,
coordinates: null,
place: null,
contributors: null,
is_quote_status: false,
quote_count: 0,
reply_count: 0,
retweet_count: 0,
favorite_count: 0,
entities: { hashtags: [ [Object] ], urls: [], user_mentions: [], symbols: [] },
favorited: false,
retweeted: false,
filter_level: 'low',
lang: 'en',
timestamp_ms: '1647326338513'
}
I want to save text: '#TelecomDisaster Test for project 2', and created_at: 'Tue Mar 15 06:38:58 +0000 2022', to my database.
I am trying with the function below to save just the text for now but i dont quite understand how to:
const express = require('express')
const router = new express.Router();
var Twitter = require('twit')
const TwitterPosts = require("../db/models/TwitterPosts.model");
//api keys goes here but it removed for safety
var stream = client.stream('statuses/filter', { track: '#TelecomDisaster' })
stream.on('tweet', function (tweet) {
console.log(tweet)
let newtweet = new TwitterPosts({
tweet: req.body.postContent
});
newtweet.save().then((twit) => {
res.send(twit);
console.log(twit);
})
});
module.exports = router;
The model for the schema:
const mongoose = require('mongoose');
const TwitterPostsSchema = new mongoose.Schema({
twitterUsername:{
type: String,
required: false,
minlength:1,
trim: true
},
postContent:{
type: String,
required: false,
minlength:1,
trim: true
},
postDateTime:{
type: Date,
required: false,
default: Date.now
}
})
const TwitterPosts = mongoose.model( 'TwitterPosts', TwitterPostsSchema);
module.exports = TwitterPosts
Whenever it trys to save i get the error
tweet: req.body.postContent
^
ReferenceError: req is not defined
i did not define req but in this use case i dont know how to do that exactly when streaming the tweets.
To conclude i am trying to save tweets to a mongoDB database using node and express. the tweets are streamed as shown above but i dont quite understand how it is saved to the database.
you receive tweet in stream.on listener, so it's just tweet, instead of req.body.postContent:
let newtweet = new TwitterPosts({
tweet: tweet
});
or, according to your schema:
let newtweet = new TwitterPosts({
twitterUsername: tweet.user.name,
postContent: tweet.text,
postDateTime: tweet.created_at
});
I've built a few functions to table channel & category information, one of which runs when the bot starts to make sure everything is synced.
The problem I've run into is that bot.channels.cache contains channels that no longer exist, or states of a channel that no longer exists. For example, I only have one channel in the server called "general". Yet, there are 3 separate entries for that channel by name, and only one contains the ID (711043006781849686) of the current "general" channel:
import Discord from 'discord.js'
import config from '../config.js'
const bot = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] })
bot.login(config.botToken)
bot.on('ready', async () => {
console.log(bot.channels.cache)
}
-- returns --
Collection(46) [Map] {
...
'711043006781849686' => <ref *16> TextChannel {
type: 'text',
deleted: false,
id: '711043006781849686',
name: 'general',
rawPosition: 10,
parentID: '711043007197216880',
permissionOverwrites: Collection(3) [Map] {
'711043006253367426' => [PermissionOverwrites],
'711043006295179347' => [PermissionOverwrites],
'861109585930747934' => [PermissionOverwrites]
},
topic: 'General chat channel.',
nsfw: false,
lastMessageID: '860794574707752980',
rateLimitPerUser: 0,
lastPinTimestamp: null,
guild: Guild {
members: [GuildMemberManager],
channels: [GuildChannelManager],
roles: [RoleManager],
presences: [PresenceManager],
voiceStates: [VoiceStateManager],
deleted: false,
available: true,
id: '711043006253367426',
shardID: 0,
name: 'Omegabox',
icon: null,
splash: null,
discoverySplash: null,
region: 'us-central',
memberCount: 5,
large: false,
features: [Array],
applicationID: null,
afkTimeout: 900,
afkChannelID: '711043009944223832',
systemChannelID: '711043006781849686',
embedEnabled: undefined,
premiumTier: 0,
premiumSubscriptionCount: 0,
verificationLevel: 'NONE',
explicitContentFilter: 'DISABLED',
mfaLevel: 0,
joinedTimestamp: 1589597389528,
defaultMessageNotifications: 'ALL',
systemChannelFlags: [SystemChannelFlags],
maximumMembers: 100000,
maximumPresences: null,
approximateMemberCount: null,
approximatePresenceCount: null,
vanityURLCode: null,
vanityURLUses: null,
description: null,
banner: null,
rulesChannelID: null,
publicUpdatesChannelID: null,
preferredLocale: 'en-US',
ownerID: '598729034867933195',
emojis: [GuildEmojiManager]
},
messages: MessageManager {
cacheType: [class LimitedCollection extends Collection],
cache: [LimitedCollection [Map]],
channel: [Circular *16]
},
_typing: Map(0) {}
},
...
'827343616678559757' => <ref *33> TextChannel {
type: 'text',
deleted: false,
id: '827343616678559757',
name: 'general',
rawPosition: 0,
parentID: '827343616678559755',
permissionOverwrites: Collection(0) [Map] {},
topic: null,
lastMessageID: '830245759152291860',
rateLimitPerUser: 0,
lastPinTimestamp: null,
guild: Guild {
members: [GuildMemberManager],
channels: [GuildChannelManager],
roles: [RoleManager],
presences: [PresenceManager],
voiceStates: [VoiceStateManager],
deleted: false,
available: true,
id: '827343616678559754',
shardID: 0,
name: 'Megabox Emojis 1',
icon: null,
splash: null,
discoverySplash: null,
region: 'us-west',
memberCount: 3,
large: false,
features: [],
applicationID: null,
afkTimeout: 300,
afkChannelID: null,
systemChannelID: '827343616678559757',
embedEnabled: undefined,
premiumTier: 0,
premiumSubscriptionCount: 0,
verificationLevel: 'NONE',
explicitContentFilter: 'DISABLED',
mfaLevel: 0,
joinedTimestamp: 1617380998194,
defaultMessageNotifications: 'ALL',
systemChannelFlags: [SystemChannelFlags],
maximumMembers: 100000,
maximumPresences: null,
approximateMemberCount: null,
approximatePresenceCount: null,
vanityURLCode: null,
vanityURLUses: null,
description: null,
banner: null,
rulesChannelID: null,
publicUpdatesChannelID: null,
preferredLocale: 'en-US',
ownerID: '598729034867933195',
emojis: [GuildEmojiManager]
},
messages: MessageManager {
cacheType: [class LimitedCollection extends Collection],
cache: [LimitedCollection [Map]],
channel: [Circular *33]
},
nsfw: false,
_typing: Map(0) {}
},
...
'827344454259703842' => <ref *34> TextChannel {
type: 'text',
deleted: false,
id: '827344454259703842',
name: 'general',
rawPosition: 0,
parentID: '827344454259703840',
permissionOverwrites: Collection(0) [Map] {},
topic: null,
lastMessageID: '827580681730261032',
rateLimitPerUser: 0,
lastPinTimestamp: null,
guild: Guild {
members: [GuildMemberManager],
channels: [GuildChannelManager],
roles: [RoleManager],
presences: [PresenceManager],
voiceStates: [VoiceStateManager],
deleted: false,
available: true,
id: '827344454259703838',
shardID: 0,
name: 'Megabox Emojis 2',
icon: null,
splash: null,
discoverySplash: null,
region: 'us-west',
memberCount: 3,
large: false,
features: [],
applicationID: null,
afkTimeout: 300,
afkChannelID: null,
systemChannelID: '827344454259703842',
embedEnabled: undefined,
premiumTier: 0,
premiumSubscriptionCount: 0,
verificationLevel: 'NONE',
explicitContentFilter: 'DISABLED',
mfaLevel: 0,
joinedTimestamp: 1617381010142,
defaultMessageNotifications: 'ALL',
systemChannelFlags: [SystemChannelFlags],
maximumMembers: 100000,
maximumPresences: null,
approximateMemberCount: null,
approximatePresenceCount: null,
vanityURLCode: null,
vanityURLUses: null,
description: null,
banner: null,
rulesChannelID: null,
publicUpdatesChannelID: null,
preferredLocale: 'en-US',
ownerID: '598729034867933195',
emojis: [GuildEmojiManager]
},
messages: MessageManager {
cacheType: [class LimitedCollection extends Collection],
cache: [LimitedCollection [Map]],
channel: [Circular *34]
},
nsfw: false,
_typing: Map(0) {}
}
}
I'm aware that there is a category named "General" (ID: 711043007197216880), but the casing is different which is maintained in an entry. I've filtered that one out, along with everything else that isn't "general" from the above block.
What am I missing here? Possible to sync things up?
Always have an epiphany right after finally making a post.
Been at this for hours and never realized that in this specific call I'm not specifying what guild, or rather what server. The bot is in multiple servers, and I've already got the current server's ID in the config I'm working with.
Changed bot.channels.cache to bot.guilds.cache.get(config.guildId).channels.cache.
i am facing a problem relating to twitter bot. i was simply trying to get the tweeets with '#topi' mentioned in their status and then send them a reply and also retweet the tweet.
this is how i expect to execute the bot.
wait for tweets
receives the tweet
write the tweet to a local file (just to examine)
reply the tweet with their user_id mentioned
retweet their tweet
wait for next tweet
but the problem i am facing is, up to replying and retweeting it's working well, but since it retweeted the received tweet with the same hashtag in the status it repeats the same procedure for the hashtag as before and receives 'duplicate content error'.
is there anything quick solution for this.
require("dotenv").config();
const twit = require("twit");
const fs = require("fs");
const path = require("path");
const { resolve } = require("path");
const twitter = new twit({
consumer_key: process.env.TWITTER_API_KEY,
consumer_secret: process.env.TWITTER_API_SECRET,
access_token: process.env.TWITTER_ACCESS_TOKEN,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
});
console.log("starting bot...");
// function getTweets() {
// const getTweetParams = {
// q: "#birkhe",
// count: 10,
// };
// twitter.get("search/tweets", getTweetParams, (err, data, response) => {
// return console.log(data);
// postTweet();
// });
// }
// var Nepal = ["84.1240", "28.3949"];
var stream = twitter.stream("statuses/filter", {
track: "#topi"
// geo: Nepal
});
console.log("waiting for tweets...");
console.log('----------------------');
stream.on("tweet", async (tweet) => {
console.log("writing received tweets to a file...");
fs.writeFileSync(path.join(__dirname, "tweets.json"), JSON.stringify(tweet));
console.log("writing tweet to a file is completed...");
console.log('----------------------');
const user_name = tweet.user.screen_name;
const name = tweet.user.name;
const tweetId = tweet.id_str;
const receivedTewwtText = tweet.text;
console.log("user Name id:", user_name);
console.log("name id:", name);
console.log("tweetId:", tweetId);
console.log("received text:", receivedTewwtText);
const tweetText = `#${user_name} have a good day!`;
try{
await replyTweet(tweetText);
await retweet(tweetId);
}catch(e){
console.log("the Error is ", e);
}
});
function retweet(id) {
return new Promise((reject, resolve) => {
console.log("posting retweet...");
let postRetweetParams = {
id,
};
twitter.post("statuses/retweet/:id", postRetweetParams, (err, data) => {
if (err) {
console.log("there is an error while posting retweet..");
return reject(err);
}
console.log("retweeted successfully...");
console.log('----------------------');
return resolve(data);
});
});
}
function replyTweet(text) {
return new Promise((resolve, reject) => {
console.log("replting tweet...");
let postTweetParams = {
status: text,
};
twitter.post("statuses/update", postTweetParams, (err, data) => {
if (err) {
console.log("there is an error while replting to a tweet...");
return reject(err);
}
console.log("reply tweet ID is, ", data.id_str);
console.log("replting twit completed...");
console.log('----------------------');
return resolve(data);
});
});
}
starting bot...
waiting for tweets...
----------------------
writing received tweets to a file...
writing tweet to a file is completed...
----------------------
user Name id: LaxmanP71300671
name id: Laxman Pokhrel
tweetId: 1410595913265938445
received text: Hello there #topi
replting tweet...
reply tweet ID is, 1410595936984731648
replting twit completed...
----------------------
posting retweet...
retweeted successfully...
----------------------
the Error is {
created_at: 'Thu Jul 01 13:47:34 +0000 2021',
id: 1410595939673206800,
id_str: '1410595939673206792',
text: 'RT #LaxmanP71300671: Hello there #topi',
truncated: false,
entities: {
hashtags: [ [Object] ],
symbols: [],
user_mentions: [ [Object] ],
urls: []
},
source: 'बिर्खे',
in_reply_to_status_id: null,
in_reply_to_status_id_str: null,
in_reply_to_user_id: null,
in_reply_to_user_id_str: null,
in_reply_to_screen_name: null,
user: {
id: 1407231034958094300,
id_str: '1407231034958094337',
name: 'बिर्खे',
screen_name: 'webtron_birkhe',
location: 'Kathmandu, Nepal',
description: 'म बिर्खे हुँ । म हजुरको सेवामा चौबिसै घण्टा उपलब्ध छु ।',
url: '/*some url*/',
entities: { url: [Object], description: [Object] },
protected: false,
followers_count: 2,
friends_count: 25,
listed_count: 0,
created_at: 'Tue Jun 22 06:57:05 +0000 2021',
favourites_count: 0,
utc_offset: null,
time_zone: null,
geo_enabled: false,
verified: false,
statuses_count: 9,
lang: null,
contributors_enabled: false,
is_translator: false,
is_translation_enabled: false,
profile_background_color: 'F5F8FA',
profile_background_image_url: null,
profile_background_image_url_https: null,
profile_background_tile: false,
profile_image_url: 'http://pbs.twimg.com/profile_images/1407232001204129793/47DUsEQN_normal.jpg',
profile_image_url_https: 'https://pbs.twimg.com/profile_images/1407232001204129793/47DUsEQN_normal.jpg',
profile_banner_url: 'https://pbs.twimg.com/profile_banners/1407231034958094337/1624973880',
profile_link_color: '1DA1F2',
profile_sidebar_border_color: 'C0DEED',
profile_sidebar_fill_color: 'DDEEF6',
profile_text_color: '333333',
profile_use_background_image: true,
has_extended_profile: true,
default_profile: true,
default_profile_image: false,
following: false,
follow_request_sent: false,
notifications: false,
translator_type: 'none',
withheld_in_countries: []
},
geo: null,
coordinates: null,
place: null,
contributors: null,
retweeted_status: {
created_at: 'Thu Jul 01 13:47:27 +0000 2021',
id: 1410595913265938400,
id_str: '1410595913265938445',
text: 'Hello there #topi',
truncated: false,
entities: { hashtags: [Array], symbols: [], user_mentions: [], urls: [] },
source: 'Twitter for Android',
in_reply_to_status_id: null,
in_reply_to_status_id_str: null,
in_reply_to_user_id: null,
in_reply_to_user_id_str: null,
in_reply_to_screen_name: null,
user: {
id: 1348101598157840400,
id_str: '1348101598157840384',
name: 'Laxman Pokhrel',
screen_name: 'LaxmanP71300671',
location: 'Nepal',
description: 'rock🤟',
url: null,
entities: [Object],
protected: false,
followers_count: 2,
friends_count: 18,
listed_count: 0,
created_at: 'Sun Jan 10 02:57:39 +0000 2021',
favourites_count: 4,
utc_offset: null,
time_zone: null,
geo_enabled: false,
verified: false,
statuses_count: 6,
lang: null,
contributors_enabled: false,
is_translator: false,
is_translation_enabled: false,
profile_background_color: 'F5F8FA',
profile_background_image_url: null,
profile_background_image_url_https: null,
profile_background_tile: false,
profile_image_url: 'http://pbs.twimg.com/profile_images/1348102053713727489/xpMY6o-d_normal.jpg',
profile_image_url_https: 'https://pbs.twimg.com/profile_images/1348102053713727489/xpMY6o-d_normal.jpg',
profile_banner_url: 'https://pbs.twimg.com/profile_banners/1348101598157840384/1610247852',
profile_link_color: '1DA1F2',
profile_sidebar_border_color: 'C0DEED',
profile_sidebar_fill_color: 'DDEEF6',
profile_text_color: '333333',
profile_use_background_image: true,
has_extended_profile: true,
default_profile: true,
default_profile_image: false,
following: false,
follow_request_sent: false,
notifications: false,
translator_type: 'none',
withheld_in_countries: []
},
geo: null,
coordinates: null,
place: null,
contributors: null,
is_quote_status: false,
retweet_count: 1,
favorite_count: 0,
favorited: false,
retweeted: true,
lang: 'en'
},
is_quote_status: false,
retweet_count: 1,
favorite_count: 0,
favorited: false,
retweeted: true,
lang: 'en'
}
writing received tweets to a file...
writing tweet to a file is completed...
----------------------
user Name id: webtron_birkhe
name id: बिर्खे
tweetId: 1410595939673206792
received text: RT #LaxmanP71300671: Hello there #topi
replting tweet...
reply tweet ID is, 1410595963484270594
replting twit completed...
----------------------
posting retweet...
there is an error while posting retweet..
please help.
I am doing stripe subscription using node js Api's when i go to subscription under dashboard its created subscription but it gives status incomplete,no payment deduction occurs
if i am doing through dashboard its create the subscription with active status
id: 'sub_INTyoOKF5bt1ib',
object: 'subscription',
application_fee_percent: null,
billing_cycle_anchor: 1605199862,
billing_thresholds: null,
cancel_at: null,
cancel_at_period_end: false,
canceled_at: null,
collection_method: 'charge_automatically',
created: 1605199862,
current_period_end: 1605286262,
current_period_start: 1605199862,
customer: 'cus_INTyfeuOhg9XDC',
days_until_due: null,
default_payment_method: null,
default_source: null,
default_tax_rates: [],
discount: null,
ended_at: null,
items: {
object: 'list',
data: [ [Object] ],
has_more: false,
total_count: 1,
url: '/v1/subscription_items?subscription=sub_INTyoOKF5bt1ib'
},
latest_invoice: 'in_1Hmj0lLm4uTMGNUSyogmK9TA',
livemode: true,
metadata: {},
next_pending_invoice_item_invoice: null,
pause_collection: null,
pending_invoice_item_interval: null,
pending_setup_intent: null,
pending_update: null,
plan: {
id: 'price_1HlYMvLm4uTMGNUSarJML52T',
object: 'plan',
active: true,
aggregate_usage: null,
amount: 100,
amount_decimal: '100',
billing_scheme: 'per_unit',
created: 1604920625,
currency: 'inr',
interval: 'day',
interval_count: 1,
livemode: true,
metadata: {},
nickname: null,
product: 'prod_IMGu6PI2mJbBCi',
tiers_mode: null,
transform_usage: null,
trial_period_days: null,
usage_type: 'licensed'
},
quantity: 1,
schedule: null,
start_date: 1605199862,
status: 'incomplete',
transfer_data: null,
trial_end: null,
trial_start: null
}
*********latest invoice and payment intent
id: 'sub_INkoNdFnS5DaZR',
object: 'subscription',
application_fee_percent: null,
billing_cycle_anchor: 1605262511,
billing_thresholds: null,
cancel_at: null,
cancel_at_period_end: false,
canceled_at: null,
collection_method: 'charge_automatically',
created: 1605262511,
current_period_end: 1605348911,
current_period_start: 1605262511,
customer: 'cus_INkoPwPjgIyGbV',
days_until_due: null,
default_payment_method: null,
default_source: null,
default_tax_rates: [],
discount: null,
ended_at: null,
items: {
object: 'list',
data: [ [Object] ],
has_more: false,
total_count: 1,
url: '/v1/subscription_items?subscription=sub_INkoNdFnS5DaZR'
},
latest_invoice: {
id: 'in_1HmzJDLm4uTMGNUSmbbqqwR7',
object: 'invoice',
account_country: 'IN',
account_name: 'Walkify',
account_tax_ids: null,
amount_due: 100,
amount_paid: 0,
amount_remaining: 100,
application_fee_amount: null,
attempt_count: 0,
attempted: true,
auto_advance: true,
billing_reason: 'subscription_create',
charge: null,
collection_method: 'charge_automatically',
created: 1605262511,
currency: 'inr',
custom_fields: null,
customer: 'cus_INkoPwPjgIyGbV',
customer_address: {
city: 'Mangaliya,Indore',
country: 'IN',
line1: '',
line2: '',
postal_code: null,
state: 'India'
},
customer_email: 'abc#gmail.com',
customer_name: 'Ravi R',
customer_phone: '',
customer_shipping: null,
customer_tax_exempt: 'none',
customer_tax_ids: [],
default_payment_method: null,
default_source: null,
default_tax_rates: [],
description: null,
discount: null,
discounts: [],
due_date: null,
ending_balance: 0,
footer: null,
hosted_invoice_url: 'https://invoice.stripe.com/i/acct_1HZVL5Lm4uTMGNUS/invst_INkotPj0f800RnPxEA5u8Lzw7IR6Dvy',
invoice_pdf: 'https://pay.stripe.com/invoice/acct_1HZVL5Lm4uTMGNUS/invst_INkotPj0f800RnPxEA5u8Lzw7IR6Dvy/pdf',
last_finalization_error: null,
lines: {
object: 'list',
data: [Array],
has_more: false,
total_count: 1,
url: '/v1/invoices/in_1HmzJDLm4uTMGNUSmbbqqwR7/lines'
},
livemode: true,
metadata: {},
next_payment_attempt: null,
number: 'A77E89AD-0001',
paid: false,
payment_intent: {
id: 'pi_1HmzJDLm4uTMGNUSRu34ggsq',
object: 'payment_intent',
amount: 100,
amount_capturable: 0,
amount_received: 0,
application: null,
application_fee_amount: null,
canceled_at: null,
cancellation_reason: null,
capture_method: 'automatic',
charges: [Object],
client_secret: 'pi_1HmzJDLm4uTMGNUSRu34ggsq_secret_7Sk56e79TEjpt3EQSI4a7CS5a',
confirmation_method: 'automatic',
created: 1605262511,
currency: 'inr',
customer: 'cus_INkoPwPjgIyGbV',
description: 'Subscription creation',
invoice: 'in_1HmzJDLm4uTMGNUSmbbqqwR7',
last_payment_error: null,
livemode: true,
metadata: {},
next_action: [Object],
on_behalf_of: null,
payment_method: 'pm_1HmzJBLm4uTMGNUSeROzE4C9',
payment_method_options: [Object],
payment_method_types: [Array],
receipt_email: null,
review: null,
setup_future_usage: 'off_session',
shipping: null,
source: null,
statement_descriptor: null,
statement_descriptor_suffix: null,
status: 'requires_action',
transfer_data: null,
transfer_group: null
},
period_end: 1605262511,
period_start: 1605262511,
post_payment_credit_notes_amount: 0,
pre_payment_credit_notes_amount: 0,
receipt_number: null,
starting_balance: 0,
statement_descriptor: null,
status: 'open',
status_transitions: {
finalized_at: 1605262511,
marked_uncollectible_at: null,
paid_at: null,
voided_at: null
},
subscription: 'sub_INkoNdFnS5DaZR',
subtotal: 100,
tax: null,
total: 100,
total_discount_amounts: [],
total_tax_amounts: [],
transfer_data: null,
webhooks_delivered_at: 1605262511
},
livemode: true,
metadata: {},
next_pending_invoice_item_invoice: null,
pause_collection: null,
pending_invoice_item_interval: null,
pending_setup_intent: null,
pending_update: null,
plan: {
id: 'price_1HlYMvLm4uTMGNUSarJML52T',
object: 'plan',
active: true,
aggregate_usage: null,
amount: 100,
amount_decimal: '100',
billing_scheme: 'per_unit',
created: 1604920625,
currency: 'inr',
interval: 'day',
interval_count: 1,
livemode: true,
metadata: {},
nickname: null,
product: 'prod_IMGu6PI2mJbBCi',
tiers_mode: null,
transform_usage: null,
trial_period_days: null,
usage_type: 'licensed'
},
quantity: 1,
schedule: null,
start_date: 1605262511,
status: 'incomplete',
transfer_data: null,
trial_end: null,
trial_start: null
}
Stripe account country is india and card is also india
I have a web application that is listening to webhook to the accounts they are connected to via oauth and for some reason every webhook that is coming in doesn't have the user_id attribute on them.
{
id: 'evt_18USWeLQuocIBkVl4x3RYTYn',
object: 'event',
api_version: '2016-06-15',
created: 1467859564,
data:
{ object:
{ id: 'ch_18USWdLQuocIBkVlfev2xN9n',
object: 'charge',
amount: 300,
amount_refunded: 0,
application_fee: null,
balance_transaction: 'txn_18USWeLQuocIBkVlYKlhfYl7',
captured: true,
created: 1467859563,
currency: 'usd',
customer: null,
description: '',
destination: null,
dispute: null,
failure_code: null,
failure_message: null,
fraud_details: {},
invoice: null,
livemode: false,
metadata: {},
order: null,
paid: true,
receipt_email: null,
receipt_number: null,
refunded: false,
refunds: [Object],
shipping: null,
source: [Object],
source_transfer: null,
statement_descriptor: null,
status: 'succeeded' } },
livemode: false,
pending_webhooks: 2,
request: 'req_8m0X3GgVB7IWpM',
type: 'charge.succeeded'
}
There are two different types of webhooks that can be set up:
"Account" webhooks will receive events that happen on your own account
"Connect" webhooks will receive events that happen on any account that is connected to your platform
Only events sent to "Connect" webhooks will include the user_id field.
If you're receiving events without a user_id field, then that means the event happened on your own account, and was sent to you via an "Account" endpoint rather than a "Connect" endpoint.