This repo contains firestore cloud functions, specifically the censor function that gets triggered everytime new message is being written to firestore. The censor function calls the backend service to get prediction of message class, and writes back the result to firestore.
- Install firebase CLI
npm install -g firebase-tools
- change working directory to
functions
folder - run
npm install
To test the firebase function locally, follow these steps.
- Initialize emulator
firebase init emulators
- Run the emulator suite
firebase emulators:start
-
Open with web browser the firestore emulator ui url given in terminal
-
Click Start Collection
-
Fill form with these data, then save. This will create a chatroom collection.
- Collection ID:
chatRooms
- Document ID:
chatroom1
- Collection ID:
-
Click start collection in
chatroom1
document -
Fill form with these data (test message safe) then save. This will add a new message to the chatroom.
- Collection ID:
messages
- Document ID:
msg1
- Field:
messageText
, Type:string
, Value:halo
- Collection ID:
-
After few seconds, the cloud function should automatically update the message. Click
msg1
document, and make sure thecensor
field is set to"SAFE"
. -
On collection
messages
, click add document. -
Fill form with these data (test message unsafe) then save.
- Document Id:
msg2
- Field:
messageText
, Type:string
, Value:kamu jelek
- Document Id:
-
After few seconds, the cloud function should automatically update the message. Click
msg2
document and make sure thecensor
field is set to"UNSAFE"
.
- Setup Google Cloud ADC https://cloud.google.com/docs/authentication/provide-credentials-adc?hl=en
- Run in terminal
firebase deploy --only functions