Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions gmail/.clasp.json

This file was deleted.

13 changes: 0 additions & 13 deletions gmail/.claspignore

This file was deleted.

2 changes: 2 additions & 0 deletions gmail/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
7 changes: 5 additions & 2 deletions gmail/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"semi": true,
"trailingComma": "all",
"singleQuote": false,
"printWidth": 120,
"tabWidth": 4
"printWidth": 100,
"tabWidth": 4,
"plugins": [
"prettier-plugin-organize-imports"
]
}
97 changes: 19 additions & 78 deletions gmail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,89 +2,30 @@
This addons allows you to find information about the sender of the emails you received
and also to link your Gmail contacts to your Odoo partners, to create leads from Gmail,...

![Odoo Gmail Extension](./assets/img/readme.png)

# Development
## Requirements
First you need npm,
> apt-get install -y npm

Install the dependencies
> npm install

## Prettier
You should auto-format the code using the prettier configuration,
> `npx prettier --config .prettierrc 'src/**/*.ts' --write`

## Compiling

We use [rollup.js](https://github.com/rollup/rollup) to package all of the source files into a single one.
This is necessary as App Scripts do not support ES6 import/export statements yet.

Once you have applied the necessary changes, run the following command:
> npx rollup -c

This will simultaneously compile and package the typescript sourcecode inside `build/main.js`

Now all you need to do is upload the script to your account and deploy it!

## Uploading method 1: Manually copying the file
If you do not plan on updating this script regularly, perhaps you will prefer using Google's GUI.

- Head to [the App Scripts manager](https://script.google.com/) and create a project
- Go to the project settings and enable appscript.json editing: `Show "appsscript.json" manifest file in editor`
- Copy the contents of your local `appscript.json` to the remote one in the project editor
- Create a file `main.gs` and remove the existing `Code.gs` if any.
- Copy the contents of your local `build/main.js` to the `main.gs` file in the project editor
Create the database and fill the credentials in `consts.ts`
> psql -U root -d postgres -f init_db.sql

## Uploading method 2: Using Clasp
You may want to use the Google's CLI tool [clasp](https://github.com/google/clasp) to manage, compile and update your app script.
To serve the addin, you need a public HTTPS connection to your application.
You cannot use nrgok, because Gmail store all images we use in the addin,
and it won't fetch them if they come from a free ngrok domain name.
So the simplest is to use a VPS (and to do a reverse SSH proxy to develop locally).

First install
> npm install -g @google/clasp

Login to your account to be able to push on your Gmail project,
> clasp login

Note: the `--no-localhost` option we previously recommended was [deprecated by google](https://developers.google.com/identity/protocols/oauth2/resources/oob-migration)

### If you already have a project
Update `.clasp.json` to use your own script id and project.
If you do not have a specific project, use `Default`.

### If you do not have a project yet
Remove `.clasp.json`

Create a project
> clasp create

For the project type, select "api".

### Push your project
Push the project
> clasp push


# Deployment
Finally, you can enable the add-on for your account.

Head to [the App Scripts manager](https://script.google.com/).
- Select your project and click "Deploy".
- For testing on your account just select "Test deployments". "Google Workspace Add-on" should be automatically selected as the type.
- Click "Install" and the add-on should appear in the addons tab of Gmail.
Then run
> npm install
> npm run dev

You're done!
Go to this page:
https://console.cloud.google.com/apis/api/appsmarket-component.googleapis.com/googleapps_sdk_gsao

For final deployments you will need to create a Google Cloud Project with the GMail API and link it to this script.
Refer to Google's documentation for more information.
Then create an HTTP deployment using `deployment.json`, and update the URL in `onTriggerFunction` to contain your ngrok URL.

# Documentation
`GmailApp` object,
https://developers.google.com/apps-script/reference/gmail/gmail-app
Then click on "install", and the addin will be available in your Gmail account.

`URL fetch API`
https://developers.google.com/apps-script/reference/url-fetch
Before committing, run prettier
> npm run prettier

`Storage`
https://developers.google.com/apps-script/reference/cache
https://developers.google.com/apps-script/reference/properties
# Production
Update the `CLIENT_ID` and the public URL in `consts.ts`, then run
> npm run build
> node dist
54 changes: 0 additions & 54 deletions gmail/appsscript.json

This file was deleted.

Binary file removed gmail/assets/img/odoo.png
Binary file not shown.
Binary file removed gmail/assets/img/odoo_full.png
Binary file not shown.
Binary file removed gmail/assets/img/readme.png
Binary file not shown.
26 changes: 26 additions & 0 deletions gmail/deployment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"oauthScopes": [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/gmail.addons.execute",
"https://www.googleapis.com/auth/gmail.addons.current.message.readonly"
],
"addOns": {
"common": {
"name": "Odoo",
"logoUrl": "https://raw.githubusercontent.com/odoo/mail-client-extensions/master/outlook/assets/odoo.png"
},
"gmail": {
"primaryColor": "#875A7B",
"secondaryColor": "#00A09D",
"contextualTriggers": [
{
"unconditional": {},
"onTriggerFunction": "https://mister7f.xyz/on_open_email"
}
]
},
"httpOptions": {
"granularOauthPermissionSupport": "OPT_IN"
}
}
}
13 changes: 0 additions & 13 deletions gmail/iap_instruction.md

This file was deleted.

25 changes: 25 additions & 0 deletions gmail/init_db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CREATE DATABASE gmail_addin_db;

\c gmail_addin_db;

CREATE TABLE users_settings (
id SERIAL PRIMARY KEY,
email TEXT UNIQUE NOT NULL,
odoo_url TEXT,
odoo_token TEXT,
login_token TEXT,
login_token_expire_at TIMESTAMP WITH TIME ZONE,
translations JSON,
translations_expire_at TIMESTAMP WITH TIME ZONE
);

-- Remember that the user logged the email on the giver record
CREATE TABLE email_logs (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL,
message_id TEXT NOT NULL,
res_id INTEGER NOT NULL,
res_model TEXT NOT NULL,
create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
FOREIGN KEY (user_id) REFERENCES users_settings(id) ON DELETE CASCADE
);
Loading