{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":5210,"path":"conversational-interfaces/virtual-agent/va-adapter-autolinking.md","title":"Account linking in pre-built messaging integrations","bundle":null,"doc_type":null,"release":"australia","body":"\n# Account linking in pre-built messaging integrations\n\nIn Virtual Agent, account linking maps the users of a supported chat or messaging application to their ServiceNow user profile. Account auto-linking authenticates your messaging users, which enables users to automatically access Virtual Agent topics that involve ServiceNow records. If needed, users can also manually unlink from or link to their ServiceNow accounts.\n\n## How account auto-linking works\n\nIn the Conversational Integrations for Slack, Microsoft Teams, and Workplace from Facebook, you have the option to enable account auto-linking, which automatically links messaging users to their ServiceNow accounts. If you enable the account auto-linking feature on the Messaging Apps Integration page, your users are not prompted to link to their ServiceNow accounts when they engage with the virtual agent.\n\nIn earlier releases, messaging users were prompted to link to their ServiceNow accounts or continue as guests. However, for the Conversational Integrations for Slack, Microsoft Teams, and Workplace, if you enable account auto-linking, your users do not manually link their messaging accounts to their ServiceNow accounts, provided that they use the same email account for their messaging and ServiceNow accounts. During auto-linking, Virtual Agent maps the email accounts of messaging users to their email accounts defined in their profiles in the Users \\[sys\\_user\\] table. When the email accounts match, the user is automatically linked \\(authenticated\\) and they do not see the **Link to ServiceNow** button when they begin a bot conversation.\n\nIn messaging integrations, your users can still use the **logout** command during bot conversations to unlink from their ServiceNow accounts. However, in all subsequent conversations after unlinking, Virtual Agent prompts them to link their accounts. When they engage with the virtual agent, they are prompted to link to their ServiceNow account or continue as a guest user.\n\n## Account auto-linking\n\nYou can allow a user's 3rd party accounts to be auto-linked to their ServiceNow® profile.\n\nYou can enable account auto-linking in the sys\\_cs\\_provider.list. This feature bypasses the prompt for the users to link their accounts manually.\n\n**Note:** Account linking is possible only for users who belong to the same domain that was used for installing Microsoft Teams on an instance. To auto-link users from other domains, ensure that Microsoft Teams installation is done using the global domain.\n\nIn the navigation filter type `sys_cs_provider.list`. Select the connection record you wish to link. Check the **Allow account linking** box, then check the **Auto link users' ServiceNow profiles** box that appears. Fill in the **Automatic link action** field with the corresponding account linking script.\n\nExample: Account auto-linking script\n\n```\nvar response_body = inputs['response_body'];\nvar status_code = inputs ['status_code'];\nvar email_id = '';\nif(status_code>200 && status_code<=210){\n    email_id = response_body && JSON.parse(response_body).userPrincipalName;\n}\nvar sysUserId = null;\n\nif(email_id){\n    var gr = new GlideRecord(\"sys_user\");\n    gr.addQuery(\"email\",email_id);\n    gr.query();\n    while(gr.next()){\n        sysUserId = gr.getUniqueValue();\n    }\n}\nif(sysUserId){\n    outputs['status'} = 'Success';\n    outputs['userid'] = sysUserId;\n}\nelse{\n    outputs['status'] = 'Failure';\n}\n\n})(inputs,outputs);\n```\n\n-   **[Unlink your ServiceNow user account from a messaging application for Virtual Agent conversations](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/conversational-interfaces/virtual-agent/unlink-va-messaging.md)**  \nIf needed, you can unlink your ServiceNow user account from a messaging app used for the Now Virtual Agent.\n-   **[Link your ServiceNow user account to a messaging application for Virtual Agent conversations](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/conversational-interfaces/virtual-agent/link-accounts-with-virtual-agent.md)**  \nLink your ServiceNow account to a third-party messaging application to access non-public Virtual Agent topics that use ServiceNow records.\n\n**Parent Topic:**[Integrating Virtual Agent with messaging apps](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/conversational-interfaces/virtual-agent/va-integration-messaging-apps.md)\n\n"}}