{"id":15024061,"url":"https://github.com/sap/webchat","last_synced_at":"2025-05-16T11:06:55.265Z","repository":{"id":27615394,"uuid":"114344713","full_name":"SAP/Webchat","owner":"SAP","description":"The SAP Conversational AI webchat let you deploy a bot straight to a website","archived":false,"fork":false,"pushed_at":"2025-03-24T14:01:26.000Z","size":10495,"stargazers_count":81,"open_issues_count":45,"forks_count":201,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-05-11T05:28:59.104Z","etag":null,"topics":["bot","webchat"],"latest_commit_sha":null,"homepage":"https://cai.tools.sap","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SAP.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-12-15T08:11:26.000Z","updated_at":"2025-04-04T03:38:19.000Z","dependencies_parsed_at":"2024-03-21T05:15:15.406Z","dependency_job_id":null,"html_url":"https://github.com/SAP/Webchat","commit_stats":null,"previous_names":["sapconversationalai/webchat"],"tags_count":63,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP%2FWebchat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP%2FWebchat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP%2FWebchat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAP%2FWebchat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SAP","download_url":"https://codeload.github.com/SAP/Webchat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254518383,"owners_count":22084374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","webchat"],"created_at":"2024-09-24T19:59:45.447Z","updated_at":"2025-05-16T11:06:50.255Z","avatar_url":"https://github.com/SAP.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"assets/header.png\" /\u003e\n\u003c/div\u003e\n\n# SAP Conversational AI Webchat\n| [Default Usage](#usage) | [Self-Hosted Installation](#self-hosted-webchat) | [Getting Started on SAP Conversational AI]( #getting-started-with-sap-conversational-ai) | [License](#license) |\n|---|---|---|---|\n\u003cdiv\u003e\n\u003ca href=\"https://slack.cai.tools.sap/\"\u003e💬 Questions / Comments? Join the discussion on our community Slack channel!\u003c/a\u003e\n\u003c/div\u003e\n\n[![REUSE status](https://api.reuse.software/badge/github.com/SAP/Webchat)](https://api.reuse.software/info/github.com/SAP/Webchat)\n\n## What is a webchat?\n\nThe SAP Conversational AI webchat let you **deploy a bot straight to a website**. It will be embed and available through a chat box on your pages.\nThe webchat is one of the many channels available on [SAP Conversational AI](https://cai.tools.sap), and end-to-end bot building platform.\nThis webchat is built using the [React](https://github.com/facebook/react) library, along with [Redux](https://github.com/reactjs/redux) for state managment.\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"assets/webchat-github.png\" /\u003e\n\u003c/div\u003e\n\n## Compatibility\n\nThis webchat is supported by all mobile and desktop browsers in their latest versions.\nInternet Explorer support starts at version 9.0.\n\n## Usage\n\nThree different installations on the webchat module are possible.\n- The default is the simplest and fatest route, and offers some customization options.\n- The self-hosted webchat offers even more customization option, but you'll have to deal with the hosting and maintenance of the module.\n- Use it as a React component\n\n### Default webchat\n\nTo use the webchat, you need an account on [SAP Conversational AI](https://cai.tools.sap) and a bot.\nThen, go to the **CONNECT** tab and click on **Webchat**. It will open a window that lets you adjust your webchat settings, including:\n* color scheme,\n* header customization,\n* bot and user pictures,\n* webchat logo and call to action,\n* conversation duration\n\nOnce you're satisfied with the settings, click on the **SAVE** button. A script tag appears, and you just have to copy paste it in your web page to embed the webchat. The script must be placed in the `\u003cbody\u003e` tag.\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"assets/webchat-600.gif\" /\u003e\n\u003c/div\u003e\n\n\n### Self-hosted webchat\n\nIf you want to customize your webchat even more, you can opt for a self-hosted installatiton. Just fork this project to get started!\n\n#### Installation\n\nClone the repository you forked, and install the dependencies.\n\n```\n$\u003e git clone YOUR_REPO_URL\n$\u003e cd webchat\n$\u003e npm install\n```\n\n#### Run in development mode\n\n```\n$\u003e npm run start\n```\n\n#### Eslint + prettier\n\n```\n$\u003e npm run prettier\n```\n\n#### Build for production\n\n```\n$\u003e npm run build\n```\n\n#### Use your webchat\n\nOnce you're done, build it and host it.\nTo use it instead of the default one provided by SAP Conversational AI, you need to set up the Webchat channel in the **CONNECT** tab of your bot.\nYou'll be using the same script as the default installation, but you have **to replace the src field by your own URL**.\n\n\n```\n\u003cscript\n  src=\"YOUR_WEBCHAT_URL\"\n  ...\n\u003e\u003c/script\u003e\n```\n\n### React component\nYou can import the webchat as a React component like the following example:\n``` js\nimport CaiWebchat from 'webchat';\n\nexport default class ReactWebchat extends Component {\n  render() {\n    return (\n      \u003cCaiWebchat\n        onRef={ref =\u003e {\n          this.webchat = ref;\n        }}\n        channelId={YOUR_CHANNEL_ID}\n        token={YOUR_TOKEN}\n        preferences={{\n          accentColor: '#E05A47',\n          complementaryColor: '#FFFFFF',\n          botMessageColor: '#707070',\n          botMessageBackgroundColor: '#F6F6F6',\n          backgroundColor: '#FFFFFF',\n          headerLogo: 'https://cdn.cai.tools.sap/webchat/webchat-logo.svg',\n          headerTitle: 'My awesome chatbot',\n          botPicture: 'https://cdn.cai.tools.sap/webchat/bot.png',\n          userPicture: 'https://cdn.cai.tools.sap/webchat/user.png',\n          onboardingMessage: 'Come speak to me!',\n          expanderLogo: 'https://cdn.cai.tools.sap/webchat/webchat-logo.svg',\n          expanderTitle: 'Click on me!',\n          conversationTimeToLive: 24,\n          openingType: 'never',\n          welcomeMessage: 'Hello world !',\n        }}\n        getLastMessage={message =\u003e {\n          console.log(message)\n        }}\n      /\u003e\n    );\n  }\n}\n```\n\n#### Props\n|Name|Type|Required|Description|\n|---|---|---|--|\n|onRef|function|false| Function which returns ref of the webchat|\n|channelId|string|true|Channel id (you can get in SAP Conversational AI)|\n|token|string|true|Token (you can get in React.ai)|\n|preferences|object|true| Object containing some settings|\n|getLastMessage|function|false|Function which returns the last message sent by the webchat\n\n#### Methods\nYou can access these methods by using the reference of the component (use `OnRef`)\n```\n\u003cCaiWebchat\n  onRef={ref =\u003e this.webchat = ref }\n\u003e\n...\n\nthis.webchat.clearMessages();\n```\n|Name|Description|\n|---|---|\n|clearMessages()|Clear all messages in the webchat|\n\n### Bot Memory management\nOne thing you might want to do is to send custom data from your website to the bot, like the name of the logged in user, his ID, the page he is currently on (to send product suggestions for example). To do that, you can define a `window.webchatMethods.getMemory` function, the webchat will call it before sending user messages, and send your arbitrary payload along with the message to the bot.\n\nIf you use SAP Conversational AI's bot-builder (you should :)), your payload will be put in the memory of the conversation, meaning that you will be able to access this data in your bot-builder. Let's say you send this as payload : `{ \"userName\": \"Dominik\", \"userId\": 123456 }`, you will then be able to send this as a greeting message : `Hello {{ memory.userName }} ! How do you do ?`.\n\n`window.webchatMethods.getMemory` must return a JSON object or a Promise resolving a JSON object :\n  - `{ \"memory\": { ... }, \"merge\": \u003cboolean\u003e }`\nwhere `{ ... }` is your arbitrary payload. `merge` is an instruction for the bot-builder. If set to true, the payload will be merged with the existing memory, overriding common keys but keeping the ones absent from the payload. If set to false, the memory will be replaced entirely by your payload.\n\nIf your `getMemory` function takes more than 10 seconds, the message will be sent anyway, without waiting for your function to finish.\n\n#### Examples :\n```html\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cscript\u003e\n      window.webchatMethods = {\n        // called at each user message\n        getMemory: (conversationId) =\u003e {\n          const memory = { userName: 'Dominik Bousquet', userId: 123456 }\n          return { memory, merge: true }\n        }\n      }\n    \u003c/script\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cscript src=\"https://cdn.cai.tools.sap/webchat/webchat.js\"\n      channelId=\"\u003cchannelId\u003e\"\n      token=\"\u003ctoken\u003e\"\n      id=\"cai-webchat\"\n    \u003e\u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n```javascript\nwindow.webchatMethods = {\n  getMemory: (conversationId) =\u003e {\n    const getCookie = (name) =\u003e {\n      const value = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)')\n      return value ? value[2] : null\n    }\n    const userName = getCookie('userName')\n    const memory = { userName, currentUrl: window.location.href }\n    return { memory, merge: true }\n  }\n}\n```\n\n```javascript\nwindow.webchatData = {}\nwindow.webchatMethods = {\n  getMemory: (conversationId) =\u003e {\n    if (window.webchatData.savedUserData) {\n      return { memory: window.webchatData.savedUserData, merge: true }\n    }\n    return new Promise((resolve, reject) =\u003e {\n      axios.get('/current_user')\n        .then((response) =\u003e {\n          const memory = { userName: response.data.name, userId: response.data.id }\n          window.webchatData.savedUserData = memory\n          resolve({ memory, merge: true })\n        })\n        .catch(reject)\n    })\n  }\n}\n```\n\n```javascript\nwindow.webchatData = {}\nwindow.webchatMethods = {\n  getMemory: (conversationId) =\u003e {\n    if (!window.webchatData.oriUrl) {\n      window.webchatData.oriUrl = window.location.href\n    }\n    // merge: false - reset the conversation if the user\n    // switched to another page since the first message\n    if (window.webchatData.oriUrl !== window.location.href) {\n      return { memory: {}, merge: false }\n    }\n    return { memory: { userName: 'Dominik' }, merge: true }\n  }\n}\n```\n\n\n## Getting started with SAP Conversational AI\n\nWe build products to help enterprises and developers have a better understanding of user inputs.\n\n-   **NLP API**: a unique API for text processing, and augmented training.\n-   **Bot Building Tools**: all you need to create smart bots powered by SAP Conversational AI's NLP API. Design even the most complex conversation flow, use all rich messaging formats and connect to external APIs and services.\n-   **Bot Connector API**: standardizes the messaging format across all channels, letting you connect your bots to any channel in minutes.\n\nLearn more about:\n\n| [API Documentation](https://cai.tools.sap/docs/api-reference/) | [Discover the platform](https://cai.tools.sap/docs/create-your-bot) | [First bot tutorial](https://cai.tools.sap/blog/build-your-first-bot-with-cai-ai/) | [Advanced NodeJS tutorial](https://cai.tools.sap/blog/nodejs-chatbot-movie-bot/) | [Advanced Python tutorial](https://cai.tools.sap/blog/python-cryptobot/) |\n|---|---|---|---|---|\n\n## License\n\nCopyright (c) [2016] SAP Conversational AI\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"),\nto deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,\nand/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsap%2Fwebchat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsap%2Fwebchat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsap%2Fwebchat/lists"}