You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 11, 2022. It is now read-only.
### Install and configure Firebase CLI (https://developers.google.com/actions/tools/fulfillment-hosting)
34
+
### Install and configure Firebase CLI
35
35
36
36
1. In your terminal run `npm i -g firebase-tools`
37
37
2. Run command `firebase login`
@@ -47,6 +47,8 @@ Do you want to add more dynamic responses to your intents? Feel free to use this
47
47
6. Choose (n) not to install dependencies
48
48
7. You should see message "Firebase initialization complete!"
49
49
50
+
Note: more detailed instructions are available as this [Actions on Google guide](https://developers.google.com/actions/tools/fulfillment-hosting)
51
+
50
52
### Install project dependencies
51
53
52
54
1. Run command `npm i --only=dev`
@@ -107,36 +109,48 @@ You can test your manager by adding as a dependency to the `src/TestApp.ts` and
107
109
108
110
If you would to automatically reload and execute when source code is changed, run `gulp watch-changes` and in another terminal window run `gulp monitor-local`. If you make any changes in `.ts` files, project will be automatically recompiled using `tsc` and then executed with use of `nodemon`.
109
111
110
-
### Add a storage [WIP]
112
+
### Add a storage
113
+
114
+
Sometimes you need a collection of items you want to use in your business logic. Creating a black-box storage is the best practice. You can use several storages which you can swap in dependency injection container, i.e. local storage with hardcoded collection of items and Firebase storage to fetch data from Firebase database.
111
115
112
116
#### Use Firebase database as a storage [WIP]
113
117
118
+
If you want to use your database in your Firebase project as a storage, create
119
+
114
120
* Add service-account.json
115
121
* Fill database url to FirebaseUtils
116
122
117
-
### Misc
123
+
### Add class to Dependency injection framework
118
124
119
-
* If you want to use external APIs, you must upgrade your Firebase account to Blaze plan
125
+
Imagine you have an interface `DataStorage` and implementations `LocalDataStorage` and `FirebaseDataStorage`. Then you can these dependency as follows:
120
126
121
-
### Add class to Dependency injection framework
127
+
* Add interface definition to `functions/src/di/types.ts` as shown here:
128
+
129
+
```typescript
130
+
DataStorage: Symbol("DataStorage")
131
+
```
122
132
123
-
* Add class to DI functions/src/di/types.ts as
133
+
* Add binding to symbol from `types.ts` in `functions/src/di/baseContainer.ts`
* Add binding to symbol from types.ts in functions/src/di/baseContainer.ts
141
+
Above we've defined that `DataStorage` dependency will be resolved to `LocalDataStorage`. If you want to change resolve to different implementation, then you can change it here without the touching your business logic.
142
+
143
+
If you want to resolve class to instance of the same class, you can safely use this:
### Use a dependency from Dependency injection framework
151
+
### Use a dependency from dependency injection framework
138
152
139
-
If you want to use class from Dependency injection, then define it in a constructor:
153
+
If you want to use class from dependency injection, then define it in a constructor with `@inject` annotation:
140
154
141
155
```typescript
142
156
constructor(
@@ -146,20 +160,76 @@ constructor(
146
160
147
161
Then you can use member property `customClassInstance` in this class.
148
162
149
-
### Get something from network [WIP]
163
+
### Use third-party API
164
+
165
+
If you want to communicate with third-party API to retrieve or post data, you can use class `src/utils/network/Request`. This class use well known `superagent` library to make network requests. Define the `Request` dependency in you manager and then use it e.g. as follows:
Note: If you want to use external APIs, you must upgrade your Firebase account to Blaze plan.
152
177
153
-
### Directory structure [WIP]
178
+
### Use the Logger class
179
+
180
+
If you want to debug to your console and Firebase functions log, you can use class `src/utils/log/Logger` as a dependency. Then you can call methods `trace`, `debug`, `info`, `warn`, `error`, `fatal`. Logger internally use `fancylog` library.
181
+
182
+
### Send message to your Slack
183
+
184
+
If you want to send message to your Slack channel as a part of your fulfillment, then create an Incoming Webhook as instructed here: https://api.slack.com/incoming-webhooks. Then create your slack hook as an implementation of `src/utils/slack/hooks/SlackHook.ts` in `src/utils/slack/hooks/impl`. Then use `SlackUtils.sendMessage` method.
185
+
186
+
### Directory structure
187
+
188
+
```
189
+
app
190
+
└───functions ... this functions project will be deployed to Firebase Functions
191
+
│ └───src
192
+
│ │ └───config ... configuration files
193
+
│ │ └───di ... dependency injection configuration for the functions project
194
+
│ │ └───fulfillments ... fulfillments logic
195
+
│ │ └───managers ... classes with business logic for your fulfillments
196
+
│ │ └───model ... models which is used in the project
│ │ package.json ... dependencies for the functions project
202
+
│ │ tsconfig.json ... TypeScript configuration for the functions project
203
+
└───src ... main project for testing locally
204
+
│ └───di ... dependency injection for the main project
205
+
│ │ │ container.ts
206
+
│ │ │ types.ts
207
+
│ │ main.ts ... entry point for executing TestApp
208
+
│ │ TestApp.ts ... main class for testing locally
209
+
| firebase.json ... location of the functions project
210
+
│ gulpfile.js ... configuration for the Gulp build system
211
+
│ nodemon.js ... configuration for the Nodemon, tool for monitoring changes in code
212
+
│ package.json ... dependencies for the main project
213
+
│ README.md ... this readme
214
+
│ tsconfig.json ... TypeScript configuration for the main project
215
+
```
154
216
155
217
### See Firebase Functions log
156
218
157
219
If your Firebase function is not working, most likely you'll find some useful info in Firebase console. Choose `Develop > Functions > Log`
158
220
159
-
## Background
221
+
## Actions build with this project
222
+
223
+
- (your project)
224
+
225
+
## Support
160
226
161
-
This project was created as a base for project at "Ok, Google, do a hackathon" which was held in December 2018 in coworking center [Vault 42](http://www.vault42.cz), Olomouc, Czech Republic. Our team built voice receptionist which is now in use by the coworking center.
227
+
Feel free to use this project for building your actions. Pull request welcome.
228
+
229
+
If you like to support me, buy me a beer using this PayPal link: [paypal.me/novalu](https://www.paypal.com/paypalme/my/profile). Thank you!
This project was created as a base for project at "[Ok, Google, do a hackathon](https://www.meetup.com/GDG-Olomouc/events/256177266/)" which was held in December 2018 in coworking center [Vault 42](http://www.vault42.cz), Olomouc, Czech Republic. Our team built voice receptionist which is now in use by the coworking center.
0 commit comments