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
Copy file name to clipboardExpand all lines: Package.md
+203Lines changed: 203 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,3 +86,206 @@ public function main(string... args) {
86
86
}
87
87
}
88
88
```
89
+
# Listener Module
90
+
91
+
Connects to Gmail Listener using Ballerina.
92
+
93
+
# Module Overview
94
+
95
+
The Gmail Listener Ballerina Connector provides the capability to listen the push notification for changes to Gmail mailboxes. The Gmail Listener Ballerina Connector supports to listen the changes of Gmail mailboxes such as receiving new message, receiving new thread, adding new label to a message, adding star to a message, removing label to a message, removing star to a message and receiving a new attachment with following trigger methods: `onMailboxChanges`, `onNewEmail`, `onNewThread`, `onNewLabeledEmail`, `onNewStaredEmail`, `onLabelRemovedEmail`,`onStarRemovedEmail`, `onNewAttachment`.
96
+
97
+
98
+
# Prerequisites:
99
+
100
+
* Java 11 Installed
101
+
Java Development Kit (JDK) with version 11 is required.
102
+
103
+
* Download the Ballerina [distribution](https://ballerinalang.org/downloads/)
104
+
Ballerina Swan Lake Alpha 2 is required.
105
+
106
+
* Instantiate the connector by giving authentication details in the HTTP client config. The HTTP client config has built-in support for BasicAuth and OAuth 2.0. Gmail uses OAuth 2.0 to authenticate and authorize requests. The Gmail connector can be minimally instantiated in the HTTP client config using the client ID, client secret, and refresh token.
107
+
* Client ID
108
+
* Client Secret
109
+
* Refresh Token
110
+
* Refresh URL
111
+
112
+
## Obtaining Tokens
113
+
114
+
1. Visit [Google API Console](https://console.developers.google.com), click **Create Project**, and follow the wizard to create a new project.
115
+
2. Go to **Library** from the left side menu. In the search bar enter required API/Service name(Eg: Gmail). Then select required service and click **Enable** button.
116
+
3. Go to **Credentials -> OAuth consent screen**, enter a product name to be shown to users, and click **Save**.
117
+
4. On the **Credentials** tab, click **Create credentials** and select **OAuth client ID**.
118
+
5. Select an application type, enter a name for the application, and specify a redirect URI (enter https://developers.google.com/oauthplayground if you want to use
119
+
[OAuth 2.0 playground](https://developers.google.com/oauthplayground) to receive the authorization code and obtain the refresh token).
120
+
6. Click **Create**. Your client ID and client secret appear.
121
+
7. In a separate browser window or tab, visit [OAuth 2.0 playground](https://developers.google.com/oauthplayground), select the required Gmail scopes, and then click **Authorize APIs**.
122
+
123
+
8. When you receive your authorization code, click **Exchange authorization code for tokens** to obtain the refresh token.
124
+
125
+
## Create push topic and subscription
126
+
To use Gmail Listener connector, a topic and a subscription should be configured.
127
+
128
+
1. Enable Cloud Pub/Sub API for your project which is created in [Google API Console](https://console.developers.google.com).
129
+
2. Go to [Google Cloud Pub/Sub API management console](https://console.cloud.google.com/cloudpubsub/topic/list) and create a topic([You can follow the instructions here](https://cloud.google.com/pubsub/docs/quickstart-console) and a subscription to that topic. The subscription should be a pull subscription in this case ([Find mode details here](https://cloud.google.com/pubsub/docs/subscriber))).
130
+
3. For the push subscription , an endpoint URL should be given to push the notification. This URL is the URL where the gmail listener service runs. This should be in `https` format. (If the service runs in localhost, then ngrok can be used to get an `https` URL).
131
+
4. Grant publish right on your topic. [To do this, see the instructions here](https://developers.google.com/gmail/api/guides/push#grant_publish_rights_on_your_topic).
132
+
133
+
5. Once you have done the above steps, get your topic name (It will be in the format of `projects/<YOUR_PROJECT_NAME>topics/<YOUR_TOPIC_NAME>`) from your console and give it to the `Config.toml` file as `topicName`.
134
+
135
+
136
+
## Add project configurations file
137
+
Add the project configuration file by creating a `Config.toml` file under the root path of the project structure.
138
+
This file should have following configurations. Add the token obtained in the previous step to the `Config.toml` file.
139
+
140
+
```
141
+
[ballerinax.googleapis_gmail]
142
+
refreshToken = "enter your refresh token here"
143
+
clientId = "enter your client id here"
144
+
clientSecret = "enter your client secret here"
145
+
port = "enter the port where your listener runs"
146
+
topicName = "enter your push topic name"
147
+
148
+
```
149
+
150
+
# Compatibility
151
+
152
+
| Ballerina Language Versions | Gmail API Version |
0 commit comments