diff options
Diffstat (limited to 'docs/integration.md')
-rw-r--r-- | docs/integration.md | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/docs/integration.md b/docs/integration.md index 08164fc..acbc6b5 100644 --- a/docs/integration.md +++ b/docs/integration.md | |||
@@ -87,26 +87,26 @@ Please note that the fields `id`, `name`, `version` and `config` are mandatory. | |||
87 | This is your "backend" code. Right now the options are very limited and most of the services don't need a custom handling here. If your service is relatively straight forward and has a static URL eg. _messenger.com_, _`[TEAMID]`.slack.com_ or _web.skype.com_ all you need to do to return the Ferdi Class: | 87 | This is your "backend" code. Right now the options are very limited and most of the services don't need a custom handling here. If your service is relatively straight forward and has a static URL eg. _messenger.com_, _`[TEAMID]`.slack.com_ or _web.skype.com_ all you need to do to return the Ferdi Class: |
88 | 88 | ||
89 | ```js | 89 | ```js |
90 | module.exports = (Ferdi) => Ferdi; | 90 | module.exports = Ferdi => Ferdi; |
91 | ``` | 91 | ``` |
92 | 92 | ||
93 | If your service can be hosted on custom servers, you can validate the given URL to detect if it's your server and not e.g. google.com. To enable validation you can override the function `validateServer` | 93 | If your service can be hosted on custom servers, you can validate the given URL to detect if it's your server and not e.g. google.com. To enable validation you can override the function `validateServer` |
94 | 94 | ||
95 | ```js | 95 | ```js |
96 | // RocketChat integration | 96 | // RocketChat integration |
97 | module.exports = (Ferdi) => | 97 | module.exports = Ferdi => |
98 | class RocketChat extends Ferdi { | 98 | class RocketChat extends Ferdi { |
99 | async validateUrl(url) { | 99 | async validateUrl(url) { |
100 | try { | 100 | try { |
101 | const resp = await window.fetch(`${url}/api/info`, { | 101 | const resp = await window.fetch(`${url}/api/info`, { |
102 | method: "GET", | 102 | method: 'GET', |
103 | headers: { | 103 | headers: { |
104 | "Content-Type": "application/json", | 104 | 'Content-Type': 'application/json', |
105 | }, | 105 | }, |
106 | }); | 106 | }); |
107 | const data = await resp.json(); | 107 | const data = await resp.json(); |
108 | 108 | ||
109 | return Object.hasOwnProperty.call(data, "version"); | 109 | return Object.hasOwnProperty.call(data, 'version'); |
110 | } catch (err) { | 110 | } catch (err) { |
111 | console.error(err); | 111 | console.error(err); |
112 | } | 112 | } |
@@ -147,24 +147,44 @@ overrideUserAgent() { | |||
147 | 147 | ||
148 | ### webview.js | 148 | ### webview.js |
149 | 149 | ||
150 | The `webview.js` is the actual script that will be loaded into the webview. Here you can do whatever you want to do in order perfectly integrate the service into Ferdi. For convenience, we have provided a very simple set of functions to set unread message badges (`Ferdi.setBadge()`) and inject CSS files (`Ferdi.injectCSS()`). | 150 | The `webview.js` is the actual script that will be loaded into the webview. Here you can do whatever you want to do in order perfectly integrate the service into Ferdi. For convenience, we have provided a very simple set of functions to set unread message badges (`Ferdi.setBadge()`), set active dialog title (`Ferdi.setDialogTitle()`) and inject CSS files (`Ferdi.injectCSS()`). |
151 | 151 | ||
152 | ```js | 152 | ```js |
153 | // orat.io integration | 153 | // telegram integration |
154 | module.exports = (Ferdi) => { | 154 | module.exports = Ferdi => { |
155 | const getMessages = () => { | 155 | const getMessages = () => { |
156 | let direct = 0; | 156 | let direct = 0; |
157 | let indirect = 0; | 157 | let indirect = 0; |
158 | const FerdiData = document.querySelector("#FerdiMessages").dataset; | 158 | const elements = document.querySelectorAll('.rp'); |
159 | if (FerdiData) { | 159 | for (const element of elements) { |
160 | direct = FerdiData.direct; | 160 | const subtitleBadge = element.querySelector('.dialog-subtitle-badge'); |
161 | indirect = FerdiData.indirect; | 161 | if (subtitleBadge) { |
162 | const parsedValue = Ferdi.safeParseInt(subtitleBadge.textContent); | ||
163 | if (element.dataset.peerId > 0) { | ||
164 | direct += parsedValue; | ||
165 | } else { | ||
166 | indirect += parsedValue; | ||
167 | } | ||
168 | } | ||
162 | } | 169 | } |
163 | 170 | ||
164 | Ferdi.setBadge(direct, indirect); | 171 | Ferdi.setBadge(direct, indirect); |
165 | } | 172 | }; |
173 | |||
174 | const getActiveDialogTitle = () => { | ||
175 | const element = document.querySelector('.top .peer-title'); | ||
176 | |||
177 | Ferdi.setDialogTitle(element ? element.textContent : ''); | ||
178 | }; | ||
179 | |||
180 | const loopFunc = () => { | ||
181 | getMessages(); | ||
182 | getActiveDialogTitle(); | ||
183 | }; | ||
184 | |||
185 | Ferdi.loop(loopFunc); | ||
166 | 186 | ||
167 | Ferdi.loop(getMessages); | 187 | Ferdi.injectCSS(_path.default.join(__dirname, 'service.css')); |
168 | }; | 188 | }; |
169 | ``` | 189 | ``` |
170 | 190 | ||