See this :
#bot.on(events.Album())
async def ene(event):
feedBack = await bot.send_message(
id,
file=event.messages, # event.messages is a List - meaning we're sending an album
message=f"Test",
buttons=btn_feed_back
)
await save_redis(f"{id}-car-pics", event)
await save_redis(f"{id}-status", "wait")
In the above code, I save an event in Redis, but I can't use it in other places!!! Do you have a way to save events and use it in the future??
The reason for this issue:
I want to save the addresses of stickers and images without downloading and saving them on the server (because they are uploaded once on the Telegram server and have an access address) in the database and send them to users whenever I want.
Do you have another way to do this? I searched a lot, but I didn't get any results!
from telethon.tl.types import InputDocument
doc = InputDocument(yorfile.id, yorfile.access_hash, yorfile.file_reference)
await client.send_file("#onetimeusername", doc)
find answer in this link
Related
I have read a few posts but I am confused. This is the first time I've used firebase realtime database (I've used firestore without much problems upto now).
My data looks like the following:
It gets automatically updated. I have to make a flutter app now which can read this data and write to this individual document as well. I just can get past a simple read. Could use some help please. My simple code is attached to a button. I want to then tap into the data and make a listview.
onPressed: () async {
final fb = FirebaseDatabase.instance.reference();
fb.child('turk****fault-rtdb/1buFA3****am6w32mDGon****kCeLs/Form Responses 1/').once()
.then((DataSnapshot data) {
print("Value: ${data.value}"); // prints null
print("Key: ${data.key}"); // prints Form Response 1
}).catchError((onError){
if (kDebugMode) print (onError);
});
How can I tap into each 'record' and get details out of it?
This looks off:
fb.child('turk****fault-rtdb/1buFA3****am6w32mDGon****kCeLs/Form Responses 1/').once()
You can't pass the database URL itself into the child() call.
Try this instead:
final fb = FirebaseDatabase("your database URL").reference()
fb.child('Form Responses 1').once()...
Also see: Why is the Firebase Realtime Database's data appearing as null in the console?
Edited Question :
I have an issue with Firebase Dynamic Links Packag , My goal is getting know if new user installed and opend my app for first time to give him a rewards like 10 point . I tried to search everywhere but no answer,in firebase website there is option to know if user install for first time.
My Goal is : Getting value for first time install & how to debug this code ?
initDynamicLinks when app Lanched :
void initDynamicLinks() async {
FirebaseDynamicLinks.instance.onLink(
onSuccess: (PendingDynamicLinkData dynamicLink) async {
final Uri deepLink = dynamicLink?.link;
if (deepLink != null) {
Navigator.pushNamed(context, deepLink.path);
}
},
onError: (OnLinkErrorException e) async {
print('onLinkError');
print(e.message);
}
);
final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.getInitialLink();
final Uri deepLink = data?.link;
if (deepLink != null) {
Navigator.pushNamed(context, deepLink.path);
}
}
.
You're mixing two things here.
The First-opens tab gives you the number of unique users who clicked on your Firebase Dynamic Link for the first time.
If you want to know how many unique users used your app, by clicking the Firebase Dynamic Link or not to get to your app, you have to implement the Firebase Analytics plugin to your app.
This way you'll get access to Dashboards showing you how many Unique users you have.
EDIT
Reading your comment, looks like your question is not related to your problem.
What you want here is to attribute rewards for users who invited their friends thanks to a referral link.
Since I never implemented this witout a dedicated backend, the only thing I can share is a use-case I used some time ago explaining the logic to follow to implement it.
https://firebase.google.com/docs/dynamic-links/use-cases/rewarded-referral
EDIT 2
The logic explained in the documentation is the following :
1- Generate a Dynamic Link for UserA.
2- UserA sends the Dynamic Link to someone (called UserB).
3- When UserB starts the app from a Dynamic Link, retrieve the referral informations in the app (to retrieve UserA's informations)
4- Call a route on your backend to attribute the reward to UserA (and check if UserB is really a new user in your database).
The point is, you shouldn't manage a referral/referrer relationship on the client's side (it would be way too easily abused/hacked).
It's the job of a backend (or cloud function) to manage this.
Once you have received the link clickthrough in your app use the google_analytics package to log an event.
Related thread here:
Flutter log event with google analytics
To be honest i have never used Firebase Dynamic Links , But if your Goal is to Achieve a first open or login token , you can always use the Sharedpreferences package , in my case iam using it to navigate to different pages passed on the first login value .
i think that Sharedpreferences is more reliable and easier than what you are trying to achieve with firebase
UPDATE:
what you actually want to do is make a firebase collection with IMEI numbers , when there is a new IMEI that means a new user , when that IMEI is in your collection that means that the app is not installed for the first time ,
you can use this package imei_plugin to get IMEI number and store it on firebase
Background
I'm trying to upload images to firebase storage manually (using the upload file button in the web page), however I have no clue how to later link them to a firestore document. What I have come up with (I'm unsure if it works) is copying the url for the image in the storage bucket and adding it to a string type field in the document called profilePicture. The reason I'm unable to get this to work is that I'm really new to React Native and I don't know how to properly require the images other than typing in the specific local route. Mind you also, the way I'm requiring user data such as a profile name is after logging in with email/password auth I pass the data as a param to react navigation and require it as extraData.
What I have tried
Once I've copied the image url and pasted it in the firestore document I'm doing this:
const profilePicture = props.extraData.profilePicture;
<Image source={require({profilePicture})}/>
I have also tried using backticks but that isn't working either. The error message I'm getting is:
TransformError src\screens\Profile\ProfileScreen.js: src\screens\Profile\ProfileScreen.js:Invalid call at line 27: require({
profilePicture: profilePicture
})
Note: this is an expo managed project.
Question
Is the problem in the code or in the way I'm linking both images? Maybe both? Should I require the document rather than relying on the data passed previously?
Thanks a lot in advance!
Edit 1:
I'm trying to get all info from the current user signed in, after a little research I've come to know about requiring images in this manner:
const ref = firebase.storage().ref('path/to/image.jpg');
const url = await ref.getDownloadURL();
and then I'd require the image as in <Image source={{uri: url}}/>
I get that this could be useful for something static, but I don't get how to update the ref for every single different user.
Edit 2:
Tried using the method mentioned in Edit 1, just to see what would happen, however It doesn't seem to work, the image just does not show up.
Maybe because my component is a function component rather than a class component (?
I understand that your goal is to generate, for each image that is uploaded to Cloud Storage, a Firestore document which contains a download URL.
If this is correct, one way is to use a Cloud Function that is triggered each time a new file is added to Cloud Storage. The following Cloud Function code does exactly that. You may adapt it to your exact requirements.
exports.generateFileURL = functions.storage.object().onFinalize(async object => {
try {
const bucket = admin.storage().bucket(object.bucket);
const file = bucket.file(object.name);
// You can check that the file is an image
const signedURLconfig = { action: 'read', expires: '08-12-2025' }; // Adapt as follows
const signedURLArray = await file.getSignedUrl(signedURLconfig);
const url = signedURLArray[0];
await admin.firestore().collection('profilePictures').add({ fileName: object.name, signedURL: url }) // Adapt the fields list as desired
return null;
} catch (error) {
console.log(error);
return null;
}
});
More info on the getSignedUrl() method of the Admin SDK here.
Also note that you could assign the Firestore document ID yourself, instead of having Firestore generating it as shown in the above code (with the add() method). For example, you can add to the image metadata the uid of the user and, in the Cloud Function,get this value and use this value as the Document ID.
Another possibility is to name the profile image with the user's uid.
I'm trying to make an image upload button and link it to Firebase such that each time the button is pressed, the image is sent to Firebase Storage. Here are the relevant snippets of my code:
// Files, and references
File _imageFile;
StorageReference _reference =
FirebaseStorage.instance.ref().child('myimage.jpg');
Future uploadImage() async {
// upload the image to firebase storage
StorageUploadTask uploadTask = _reference.putFile(_imageFile);
StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
// update the uploaded state to true after uploading the image to firebase
setState(() {
_uploaded = true;
});
}
// if no image file exists, then a blank container shows - else, it will upload
//the image upon press
_imageFile == null
? Container()
: RaisedButton(
color: Colors.orange[800],
child: Text("Upload to Firebase Storage"),
onPressed: () {uploadImage();}),
However, each time I press this button, the image overwrites the pre-existing image with the same name, and I was wondering if there's a way to make it so that each time I press the button, the name of the image changes, and as a result the original image isn't overridden. I'd greatly appreciate any help I could get as I'm very new to Flutter and Firebase.
Thank you!
I think you're looking for a UUID generator.
Fortunately there is a packege for that : uuid
String fileID = Uuid().v4(); // Generate uuid and store it.
Now you can use postID as name for your file.
NOTE When you upload your file you may want to generate new uuid to avoid using the old one :)
One more thing: PLEASE dont use DateTime.now() think about if two users uploaded an image at the same time !!
Basically, when you call:
FirebaseStorage.instance.ref().child('myimage.jpg');
You're uploading the file with the same name everytime:
myimage.jpg
In order to fix your problem, you just need to generate a random key for the image. There are a couple ways you could do this:
Ideally, you would use the Uuid package which is specifically for use-cases like this.
If you are set up with Firestore (the database that Firebase offers) then you can push the name of the image to the database, and have it return the DocumentID which Firestore will create a random ID for you that isn't used.
You could also use the current Date/Time (which would be considered a bad practice for major applications, but for a personal project it will serve you just fine):
DateTime.now().toString()
or
DateTime.now().toIso8601String();
Or of course, you can always write your own hashing function, based on the name of the file that you are uploading, which you would get by doing:
_imageFile.toString();
Then once you get the random name of the file, you should upload it like this:
FirebaseStorage.instance.ref().child(myImageName).putFile(_imageFile);
This maybe a late answer but hope it helps someone in future,had the same challange my solution:
I used DateTime.now().toString(),but before that i got the current logged in user UID from firebase,
then added it to every outgoing save to storage request like this
DateTime.now().toString() + (_auth.currentUser!.uid),
This made every file unique and solved the overwriting issue for me.
ARK*
Simply Add a Document Reference
DocumentReference myDoc = FirebaseFirestore.instance
.collection('COLLECTION')
.doc();
myDoc having your new Document Id.
myDoc.set({'data':'test'});
I’m creating an application where only users I create manually in firebase can log in.
The app consists of a multistep form to gather user information. For example:
Step1 ==> gather user general information
Step2 ==> information about user’s company
I want the user to be able to log back in, see the form fields populated with his data and allow him to edit them if needed.
So far I have the multi step form, that sends data to firebase. I’m using vuex and vuefire.
I understand that I can retrieve the data in two ways: before/after navigation (https://router.vuejs.org/en/advanced/data-fetching.html)
Should I create a child in the database using the currentuser uid and then reference the database using a dynamic route such as"
db.ref('forms/' + user.uid)
I'm a beginnger and I don’t know how to go about this and if it's the correct way to think about it. How would you go about retrieving the data for a specific user and push that data into each field?
There seems to exist a vuexfire https://github.com/chrisbraddock/vuefire-auth-demo could that be the way to go about this?
I'm not familiar with vuefire but I would request user data like the following
// for getting data once
let uid = firebase.auth().currentUser.uid;
let dbRef = "users/"+uid;
firebase.database().ref(dbRef).once("value", snap => {
let email = snap.val().email;
...
})
// for realtime updates
let uid = firebase.auth().currentUser.uid;
let dbRef = "users/"+uid;
firebase.database().ref(dbRef).on("value", snap => {
this.yourVueObject = snap.val().yourData
});