This page describes how to use the WOFF SDK and its APIs.
Follow the instructions below to use the WOFF SDK.
To use the WOFF SDK, you need to first initialize the WOFF app using the woff.init() method.
The woff.init() method initializes the WOFF app, allowing it to call other methods of the WOFF SDK. Run the woff.init() method when the WOFF URL is first redirected to the endpoint URL; otherwise, the INIT_FAILED error occurs and the WOFF app cannot be opened. For woffId in woff.init(), enter the WOFF ID issued when you add the WOFF app in the Developer Console.
woff .init({ woffId: "123456-abcedfg" // WOFF ID }) .then(() => { // Run the WOFF API }) .catch((err) => { // When an error occurs while initializing the app console.log(err.code, err.message); });Caution
- When you open the WOFF app, the
woff.init()method is run based on the woff.state or access_token added to the URL. To successfully complete initialization, therefore, do not change the URL before the front-end processing is completed.- Since the URL at which the WOFF app is first run includes sensitive information such as woff.state or access_token, make sure that it is not exposed to external logging tools such as Google Analytics.
Call the woff.isInClient() and woff.getOS() methods to check the environment to run the WOFF app in.
Implement various actions to run in the WOFF app.
Call the woff.openWindow() method to open a specified URL in LINE WORKS's in-app browser or an external browser.
Call the woff.sendMessage() method to send a text message to the message room where the WOFF app is open, instead of a user. The following code example sends a message, "Hello, Works!" to a message room.
document.getElementById('sendMessageButton').addEventListener('click', function(){ if (!woff.isInClient()) { sendAlertIfNoInClient(); } else { woff.sendMessage({ 'content': 'Hello, Works! ' }).then(function() { window.alert('Message sent'); }).catch(function(error){ window.alert('Error sending message:' + error); }); }});Call the woff.sendFlexMessage() method to send a message to the message room where the WOFF app is open, using a flexible template.
Run the woff.closeWindow() method to close the WOFF app.
This section describes APIs required to develop a WOFF app using the WOFF SDK.
Initializes a WOFF app. This method must be called before you call other methods. During the initialization, it gets the user's access token from LINE WORKS.
The following methods and attribute can be run before the WOFF app is initialized.
Caution
- Run the woff.init() method when the WOFF URL is first redirected to the endpoint URL; otherwise, the INIT_FAILED error occurs and the WOFF app cannot be opened.
- The woff.init() method is run based on the information such as woff.state or access_token included in the URL when a WOFF app is run. To successfully complete the initialization, therefore, do not change the URL before the front-end processing is completed.
- Since the URL at which the WOFF app is first run includes sensitive information such as woff.state or access_token, make sure that it is not exposed to external logging tools such as Google Analytics.
| Name | Type | Description |
|---|---|---|
| config | Object | WOFF app configuration |
| config.woffId | String | WOFF ID |
| successCallback | Function | Callback returned when WOFF app initialization is successful. |
| errorCallback | Function | Callback returned when WOFF app initialization fails. |
// Default implementationwoff.init( config, successCallback, errorCallback)// Using the Promise objectwoff .init({ woffId: "123456-abcedfg" // Use own woffId }) .then(() => { // Start to use woff's api }) .catch((err) => { // Error happens during initialization console.log(err.code, err.message); });// Using a callbackwoff.init({ woffId: "123456-abcedfg" }, successCallback, errorCallback);Returns the Promise object.
Performs a login in an external browser. (In an in-app browser, this method is not used because a login is performed with woff.init().)
After running the woff.login() method, you need to run the woff.init() method again.
| Name | Type | Description | Required |
|---|---|---|---|
| loginConfig | Object | Login configuration | Optional |
| loginConfig.redirectUri | String | URL to move to when a login is performed. If not specified, the user moves to the WOFF app's endpoint URL. | Optional |
| loginConfig.domain | String | Domain name It is required if SSO is enabled. | Optional |
if (!woff.isLoggedIn()) { woff.login({ redirectUri: "https://example.com/path" }); // Verifies whether domain name and path of the specified URL}None
Performs a logout. The access token is deleted.
None
woff.logout()None
Defines an action to perform after the WOFF app is initialized by running the woff.init() method.
woff.ready.then(() => { // do something you want when woff.init finishes})Even if an error occurs during the initialization, the app does not return the WoffError object or reject woff.ready.
Gets the name of the OS on which the WOFF app is run. It does not get the browser name.
None
woff.getOS()| Return value | Description |
|---|---|
| ios | iOS or iPadOS |
| android | Android |
| web | Others |
Gets the language settings for the WOFF app.
None
woff.getLanguage()Returns navigator.language of the browser where the WOFF app is run.
Gets the version of the WOFF SDK that the WOFF app is using.
None
woff.getVersion()Returns the WOFF SDK version that the WOFF app is using.
Gets the LINE WORKS version that the user is using.
None
woff.getWorksVersion()Returns the LINE WORKS version.
Caution
- This method is not available in the desktop browser.
Checks if the WOFF app is running in the WOFF browser.
None
woff.isInClient()| Return value | Description |
|---|---|
| true | It is running in the WOFF browser. |
| false | It is running in an external browser or a browser in LINE WORKS. |
Checks if the user is logged in.
None
woff.isLoggedIn()| Return value | Description |
|---|---|
| true | The user is logged in. |
| false | The user is not logged in. |
Returns the current channel ID. It is available only on mobile.
None
woff.getChannelId()Returns the Promise object.
| Return value | Description |
|---|---|
| channelId | Message room ID |
Gets the current user's access token. The WOFF app uses this access token to send user information to the server.
Note
- The scope of this access token includes all the scopes selected in the Developer Console.
When the WOFF app runs in an external browser, an access token is issued by going through the following steps:
None
woff.getAccessToken()Returns the current user's access token.
Gets the information of the message room where the WOFF app is running.
None
woff.getContext()| Return value | Description |
|---|---|
| viewType | The WOFF app's screen size (compact, tall, and full) |
| endpointUrl | Service endpoint URL |
| permanentLinkPattern | Permanent link pattern |
| clientId | Client ID |
| clientType | Client type where the WOFF app is running (PC_WEB, MOBILE_APP, PC_APP) |
{ "viewType": "external", "endpointUrl": "https://alpha-ecoapp.worksmobile.com/starter2", "permanentLinkPattern": "concat", "clientId": "_K3ELJuSyEJQlNrkjPPP", "clientType": "PC_WEB"}Gets the user's profile information.
None
woff.getProfile()Returns the Promise object.
| Return value | Description |
|---|---|
| domainId | Domain ID |
| userId | User ID |
| displayName | User name |
Sends a message to the message room where the WOFF app is open, instead of the user. The WOFF app must run in the message room to send a message.
Caution
- The
botorbot.messagescope is required to use this API.- This API is only available for the mobile app.
| Name | Type | Requirement | Description |
|---|---|---|---|
| message | Object | Y | |
| message.content | String | Y | Message to send to the message room |
woff.sendMessage({ content: 'Hello, World!'}) .then(() => { console.log('message sent'); }) .catch((err) => { console.log('error', err); });Returns the Promise object.
Sends a Flex Template message to the message room where the WOFF app is open, instead of the user. The WOFF app must run in the message room to send a message.
Caution
- The
botorbot.messagescope is required to use this API.- This API is available only for the mobile app.
| Name | Type | Requirement | Description |
|---|---|---|---|
| message | Object | Y | |
| message.flex | String | Y | Flex Template message to send to the message room |
woff.sendFlexMessage({ flex: { "type": "flex", "altText": file.name, "contents": { "type": "bubble", "size": "kilo", ... } }}) .then(() => { console.log('message sent'); }) .catch((err) => { console.log('error', err); });Returns the Promise object.
Runs the QR reader to get the QR string.
To enable the QR reader, you need to set the Scan QR option of the WOFF app.
The requirements to run the woff.scanQR() method are as follows:
woff.scanQR() .then((result) => { // result = { value: "" } }) .catch((err) => { console.log('error', err); });Returns the Promise object.
| Return value | Description |
|---|---|
| value | The string scanned by the QR reader |
Opens a specified URL in LINE WORKS's in-app browser or in an external browser. Note that it may not work as expected in an external browser.
| Name | Type | Description |
|---|---|---|
| params | Object | Parameter object |
| params.url | String | URL's absolute path |
| params.external | Indicates whether to open the URL in an external browser. - true: Open the URL in an external browser. - false: Open the URL in an in-app browser (default). |
woff.openWindow({ url: "https://developers.worksmobile.com", external: true});None
Closes the WOFF app. Note that it may not work as expected in an external browser.
None
woff.closeWindow()None
Returns an error that occurred in the WOFF SDK.
{ "code":"INIT_FAILED", "message":"Failed to init WOFF SDK"}| Name | Type | Description |
|---|---|---|
| code | String | Error code |
| message | String | Error message |
| Code | Descrption |
|---|---|
| 400 | There is a problem with the request. Check the parameters and JSON format. |
| 401 | Authorization header was not properly sent. |
| 403 | You do not have the required API scope. |
| 429 | Rate limit has been reached. Reduce the number of API calls. |
| 500 | Temporary error on the API server |
| INIT_FAILED | Failed to initialize the WOFF SDK. |
| INVALID_ARGUMENT | Invalid arguments. |
| UNAUTHORIZED | Failed to log in to LINE WORKS. Check if an access token is specified when you make an API call. |
| FORBIDDEN | Either you do not have the required permission or you use the SDK in an unsupported environment. |
| INVALID_CONFIG | Invalid console configuration |
| INVALID_ID_TOKEN | Invalid ID token |
| EXCEPTION_IN_SUBWINDOW | There is a problem with a sub window. |