WOFF SDK

This page describes how to use the WOFF SDK and its APIs.

How to use the WOFF SDK {#how-to-use-woff-sdk}

Follow the instructions below to use the WOFF SDK.

  1. Initialize the WOFF app.
  2. Check the environment for the WOFF app.
  3. Implement various actions in the WOFF app.
  4. Close the WOFF app.

Initialize the WOFF app {#init-woff-app}

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.

Check the environment for the WOFF app {#get-platform-info}

Call the woff.isInClient() and woff.getOS() methods to check the environment to run the WOFF app in.

Implement various actions in the WOFF app.

Implement various actions to run in the WOFF app.

Example 1. Open a specified URL {#open-windows}

Call the woff.openWindow() method to open a specified URL in LINE WORKS's in-app browser or an external browser.

Example 1. Send a message to a currently open message room {#send-message}

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.

Close the WOFF app {#close-woff-app}

Run the woff.closeWindow() method to close the WOFF app.

API reference {#api-reference}

This section describes APIs required to develop a WOFF app using the WOFF SDK.

woff.init() {#woff-init}

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.

  • woff.ready
  • woff.getOS()
  • woff.getVersion()
  • woff.getWorksVersion()

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.
Parameters {#woff-init-parameter}
NameTypeDescription
configObjectWOFF app configuration
config.woffIdStringWOFF ID
successCallbackFunctionCallback returned when WOFF app initialization is successful.
errorCallbackFunctionCallback returned when WOFF app initialization fails.
Example {#woff-init-sample}
// 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);
Return value {#woff-init-response}

Returns the Promise object.

woff.login() {#woff-login}

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.

Parameters {#woff-login-parameter}
NameTypeDescriptionRequired
loginConfigObjectLogin configurationOptional
loginConfig.redirectUriStringURL to move to when a login is performed.
If not specified, the user moves to the WOFF app's endpoint URL.
Optional
loginConfig.domainStringDomain 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}
Return value {#woff-login-response}

None

woff.logout() {#woff-logout}

Performs a logout. The access token is deleted.

Parameters {#woff-logout-parameter}

None

woff.logout()
Return value {#woff-logout-response}

None

woff.ready {#woff-ready}

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.

woff.getOS() {#woff-getos}

Gets the name of the OS on which the WOFF app is run. It does not get the browser name.

Parameters {#woff-getos-parameter}

None

Example {#woff-getos-sample}
woff.getOS()
Return value {#woff-getos-response}
Return valueDescription
iosiOS or iPadOS
androidAndroid
webOthers

woff.getLanguage() {#woff-getlanguage}

Gets the language settings for the WOFF app.

Parameters {#woff-getlanguage-parameter}

None

Example {#woff-getlanguage-sample}
woff.getLanguage()
Return value {#woff-getlanguage-response}

Returns navigator.language of the browser where the WOFF app is run.

woff.getVersion() {#woff-getversion}

Gets the version of the WOFF SDK that the WOFF app is using.

Parameters {#woff-getversion-parameter}

None

Example {#woff-getversion-sample}
woff.getVersion()
Return value {#woff-getversion-response}

Returns the WOFF SDK version that the WOFF app is using.

woff.getWorksVersion() {#woff-getworksversion}

Gets the LINE WORKS version that the user is using.

Parameters {#woff-getworksversion-parameter}

None

Example {#woff-getworksversion-sample}
woff.getWorksVersion()
Return value {#woff-getworksversion-response}

Returns the LINE WORKS version.

Caution

  • This method is not available in the desktop browser.

woff.isInClient() {#woff-isinclient}

Checks if the WOFF app is running in the WOFF browser.

Parameters {#woff-isinclient-parameter}

None

Example {#woff-isinclient-sample}
woff.isInClient()
Return value {#woff-isinclient-response}
Return valueDescription
trueIt is running in the WOFF browser.
falseIt is running in an external browser or a browser in LINE WORKS.

woff.isLoggedIn() {#woff-isloggedin}

Checks if the user is logged in.

Parameters {#woff-isloggedin-parameter}

None

Example {#woff-isloggedin-sample}
woff.isLoggedIn()
Return value {#woff-isloggedin-response}
Return valueDescription
trueThe user is logged in.
falseThe user is not logged in.

woff.getChannelId() {#woff.getChannelId}

Returns the current channel ID. It is available only on mobile.

Parameters {#woff.getChannelId-parameter}

None

Example {#woff.getChannelId-sample}
woff.getChannelId()
Return value {#woff.getChannelId-response}

Returns the Promise object.

Return valueDescription
channelIdMessage room ID

woff.getAccessToken() {#woff-getaccesstoken}

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:

  1. The WOFF app calls the woff.login() method.
  2. The user logs in to LINE WORKS.
  3. The WOFF app calls the woff.init() method.
Parameters {#woff-getaccesstoken-parameter}

None

Example {#woff-getaccesstoken-sample}
woff.getAccessToken()
Return value {#woff-getaccesstoken-response}

Returns the current user's access token.

woff.getContext() {#woff-getcontext}

Gets the information of the message room where the WOFF app is running.

Parameters {#woff-getcontext-parameter}

None

Example {#woff-getcontext-sample}
woff.getContext()
Return value {#woff-getcontext-response}
Return valueDescription
viewTypeThe WOFF app's screen size (compact, tall, and full)
endpointUrlService endpoint URL
permanentLinkPatternPermanent link pattern
clientIdClient ID
clientTypeClient type where the WOFF app is running (PC_WEB, MOBILE_APP, PC_APP)
Example {#woff-getcontext-response-sample}
{    "viewType": "external",    "endpointUrl": "https://alpha-ecoapp.worksmobile.com/starter2",    "permanentLinkPattern": "concat",    "clientId": "_K3ELJuSyEJQlNrkjPPP",    "clientType": "PC_WEB"}

woff.getProfile() {#woff-getprofile}

Gets the user's profile information.

Parameters {#woff-getprofile-parameter}

None

Example {#woff-getprofile-sample}
woff.getProfile()
Return value {#woff-getprofile-response}

Returns the Promise object.

Return valueDescription
domainIdDomain ID
userIdUser ID
displayNameUser name

woff.sendMessage() {#woff-sendmessage}

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 bot or bot.message scope is required to use this API.
  • This API is only available for the mobile app.
Parameters {#woff-sendmessage-parameter}
NameTypeRequirementDescription
messageObjectY
message.contentStringYMessage to send to the message room
Example {#woff-sendmessage-parameter-sample}
woff.sendMessage({    content: 'Hello, World!'})  .then(() => {    console.log('message sent');  })  .catch((err) => {    console.log('error', err);  });
Return value {#woff-sendmessage-response}

Returns the Promise object.

woff.sendFlexMessage() {#woff-sendflexmessage}

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 bot or bot.message scope is required to use this API.
  • This API is available only for the mobile app.
Parameters {#woff-sendflexmessage-parameter}
NameTypeRequirementDescription
messageObjectY
message.flexStringYFlex Template message to send to the message room
Example {#woff-sendflexmessage-example}
woff.sendFlexMessage({    flex: {            "type": "flex",            "altText": file.name,            "contents": {                    "type": "bubble",                    "size": "kilo",                    ...            }    }})  .then(() => {    console.log('message sent');  })  .catch((err) => {    console.log('error', err);  });
Return value {#woff-sendflexmessage-response}

Returns the Promise object.

woff.scanQR() {#woff-scanqr}

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:

  • iOS: LINE WORKS 3.6.0 or later
  • Android: LINE WORKS 3.6.0 or later
  • External browsers: Web browsers supporting WebRTC API (In an external browser, woff.scanQR() internally uses an external library called jsQR, so the QR reader that opens when woff.scanQR() is run depends on the jsQR specifications. The required libraries may be updated or replaced without prior notice.)
Example {#woff-scanqr-example}
woff.scanQR()  .then((result) => {    // result = { value: "" }  })  .catch((err) => {    console.log('error', err);  });
Return value {#woff-scanqr-response}

Returns the Promise object.

Return valueDescription
valueThe string scanned by the QR reader

woff.openWindow() {#woff-openwindow}

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.

Parameters {#woff-openwindow-parameter}
NameTypeDescription
paramsObjectParameter object
params.urlStringURL's absolute path
params.externalIndicates 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).
Example {#woff-openwindow-sample}
woff.openWindow({  url: "https://developers.worksmobile.com",  external: true});
Return value {#woff-openwindow-response}

None

woff.closeWindow() {#woff-closewindow}

Closes the WOFF app. Note that it may not work as expected in an external browser.

Parameters {#woff-closewindow-parameter}

None

Example {#woff-closewindow-sample}
woff.closeWindow()
Return value {#woff-closewindow-response}

None

WOFF SDK errors {#sdk-errors}

Returns an error that occurred in the WOFF SDK.

{  "code":"INIT_FAILED",  "message":"Failed to init WOFF SDK"}
NameTypeDescription
codeStringError code
messageStringError message
CodeDescrption
400There is a problem with the request. Check the parameters and JSON format.
401Authorization header was not properly sent.
403You do not have the required API scope.
429Rate limit has been reached. Reduce the number of API calls.
500Temporary error on the API server
INIT_FAILEDFailed to initialize the WOFF SDK.
INVALID_ARGUMENTInvalid arguments.
UNAUTHORIZEDFailed to log in to LINE WORKS.
Check if an access token is specified when you make an API call.
FORBIDDENEither you do not have the required permission or you use the SDK in an unsupported environment.
INVALID_CONFIGInvalid console configuration
INVALID_ID_TOKENInvalid ID token
EXCEPTION_IN_SUBWINDOWThere is a problem with a sub window.