{"id":27689421,"url":"https://github.com/sendbird/ecommerce-ai-chatbot","last_synced_at":"2025-04-25T10:05:40.158Z","repository":{"id":184941684,"uuid":"672715193","full_name":"sendbird/ecommerce-ai-chatbot","owner":"sendbird","description":"ecommerce-ai-chatbot","archived":false,"fork":false,"pushed_at":"2023-09-05T01:17:14.000Z","size":23502,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"develop","last_synced_at":"2025-04-25T10:04:51.790Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sendbird.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-07-31T02:05:32.000Z","updated_at":"2025-03-15T14:49:52.000Z","dependencies_parsed_at":"2023-07-31T03:46:44.224Z","dependency_job_id":null,"html_url":"https://github.com/sendbird/ecommerce-ai-chatbot","commit_stats":null,"previous_names":["sendbird/ecommerce-ai-chatbot"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendbird%2Fecommerce-ai-chatbot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendbird%2Fecommerce-ai-chatbot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendbird%2Fecommerce-ai-chatbot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sendbird%2Fecommerce-ai-chatbot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sendbird","download_url":"https://codeload.github.com/sendbird/ecommerce-ai-chatbot/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250796311,"owners_count":21488706,"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":[],"created_at":"2025-04-25T10:05:24.334Z","updated_at":"2025-04-25T10:05:40.135Z","avatar_url":"https://github.com/sendbird.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# [Sendbird](https://sendbird.com) Sendbird X ChatGPT E-Commerce AI Chatbot Demo\n\n[![Platform](https://img.shields.io/badge/platform-iOS-orange.svg)](https://cocoapods.org/pods/SendBirdUIKit)\n[![Languages](https://img.shields.io/badge/language-Swift-orange.svg)](https://github.com/sendbird/sendbird-uikit-ios)\n[![Commercial License](https://img.shields.io/badge/license-Commercial-green.svg)](https://github.com/sendbird/sendbird-uikit-ios/blob/main/LICENSE.md)\n\nThis demo app showcases what AI Chatbots with Sendbird can do to enhance the customer experience of your service with more personalized and comprehensive customer support.\nUtilizing OpenAI’s GPT3.5 and its Function Calling functionality, ***Sendbird helps you build a chatbot that can go extra miles: providing informative responses with the data source you feed to the bot, accommodating customer’s requests such as tracking and canceling their orders, and even recommending new products.*** Create your own next generation AI Chatbot by following the tutorial below.\n\n![e-commerce](https://github.com/sendbird/ecommerce-ai-chatbot/assets/104121286/33b39bbf-1bb9-4794-93df-eadc51ea77b7)\n\n## Prerequisites\n1. [Sendbird Account](https://dashboard.sendbird.com/)\n2. Application ID and ChatBot: Please refer to [Step1 ~ Step4](https://sendbird.com/developer/tutorials/create-an-ai-chatbot)\n\n## How to open the demo app\n1. Open Xcode Demo project\n```shell\nopen Sample/QuickStart.xcodeproj\n```\n2. Set the `applicationId` and `botId` in [`AppDelegate.swift`](https://github.com/sendbird/ecommerce-ai-chatbot/blob/develop/Sample/QuickStart/AppDelegate.swift#L13-L23)\n```swift\nstatic let botId: String = \u003c#botId: String#\u003e\n```\n\n```swift\nSendbirdUI.initialize(applicationId: \u003c#applicationID: String#\u003e)\n```\n\n## Table of Contents\n1. [Use case: E-commerce](#use-case-e-commerce)\n2. [How it works](#how-it-works)\n3. [Demo app settings](#demo-app-settings)\n4. [System Message](#system-message)\n5. [Function Calls](#function-calls)\n6. [Welcome Message and Suggestions](#welcome-message-and-suggested-replies)\n7. [UI Components](#ui-components)\n8. [Limitations](#limitations)\n\n## Use case: E-commerce\nThis demo app demonstrates the implementation of the AI Chatbot tailored for e-commerce. It includes functionalities such as ***retrieving the order list, showing order details, canceling orders, and providing recommendations.*** By leveraging ChatGPT’s new feature [Function Calling](https://openai.com/blog/function-calling-and-other-api-updates), the Chatbot now can make an API request to the 3rd party with a predefined Function Calling based on customer’s enquiry. Then it parses and presents the response in a conversational manner, enhancing overall customer experience.\n\n## How it works\n![image](https://github.com/sendbird/ecommerce-ai-chatbot/assets/104121286/819d7006-a207-461e-adad-4992bf893534)\n\n\n1. A customer sends a message containing a specific request on the client app to the Sendbird server.\n2. The Sendbird server then delivers the message to Chat GPT.\n3. Chat GPT then analyzes the message and determines that it needs to make a Function Calling request. In response, it delivers the relevant information to the Sendbird server.\n4. The Sendbird server then sends back a Function Calling request to Chat GPT. The request contains both Function Calling data Chat GPT previously sent and the 3rd party API information provided by the client app. This configuration must be set on the client-side.\n5. The 3rd party API returns a response in `data` to the Sendbird server.\n6. The Sendbird server passes the `data` to Chat GPT.\n7. Once received, Chat GPT analyzes the data and returns proper responses to the Sendbird server as `data`.\n8. The Sendbird server passes Chat GPT’s answer to the client app.\n9. The client app can process and display the answer with Sendbird Chat UIKit.\n\n***Note***: Currently, calling a 3rd party function is an experimental feature, and some logics are handled on the client-side for convenience purposes. Due to this, the current version for iOS (3.7.0 beta) will see breaking changes in the future, especially for QuickReplyView and CardView. Also, the ad-hoc support from the server that goes into the demo may be discontinued at any time and will be replaced with a proper feature on Sendbird Dashboard in the future.\n\n## Demo app settings\nTo run the demo app, you must specify `System prompt`, `Function Calls`.\n\n### System Message\n`System prompt` defines the Persona of the ChatBot, informing users of the role the ChatBot plays. For this E-Commerce AI ChatBot, It's designed to be an AI assistant that handles and manages customer orders.\n\nYou can find this setting under Chat \u003e AI Chatbot \u003e Manage bots \u003e Edit \u003e Bot settings \u003e Parameter settings \u003e System prompt.\n\n- Input example\n  \u003cimg width=\"1118\" alt=\"image\" src=\"https://github.com/sendbird/ecommerce-ai-chatbot/assets/104121286/2d63116c-3557-4b80-bbf8-12166e33a091\"\u003e\n\n```\nYou are an AI assistant that handles and manages customer orders. You will be interacting with customers who have the orders.\n\n1. Available 24/7 to assist customers with their order inquiries.\n2. Customers may request to check the status of their orders or cancel them.\n3. You have access to the customer's order list and the order details associated with it.\n4. When a customer requests to cancel an order, you need to confirm the specific order number from their order list before proceeding.\n5. Ensure confirmation for the cancellation to the customer once it has been processed successfully.\nIf a customer needs further assistance after order cancellation, be ready to provide it\n```\n\n### Function Calls\n`Function Calls` allows you to define situations where the ChatBot needs to interface with external APIs. Within `Function Calls`, you need to enter definitions for the Function and Parameters to pass to GPT, and you can define the specs of the 3rd party API to obtain the actual data of the specified Function.\n\nYou can find this setting under Chat \u003e AI Chatbot \u003e Settings \u003e Function Calls. \n\n- Example list of Function Calls\n  \u003cimg width=\"1000\" alt=\"image\" src=\"https://github.com/sendbird/ecommerce-ai-chatbot/assets/104121286/6bca33cd-3f88-41d8-a87d-af01766f92b9\"\u003e\n\n- Input example\n  \u003cimg width=\"1000\" alt=\"image\" src=\"https://github.com/sendbird/ecommerce-ai-chatbot/assets/104121286/1d3f094b-b69b-4780-a5e1-c60f63d7ef98\"\u003e\n\n\nIn addition, you can enhance user experience by streamlining the communication with a Welcome Message, Quick Replies and Button. Using Quick Replies can improve the clarity of your customer’s intention as they are presented with a list of predefined options determined by you.\n\nMock API Server Information: [Link](https://documenter.getpostman.com/view/21816899/2s9Y5eMK9o)\n\n## Welcome Message and Suggested Replies\n\u003cimg width=\"387\" alt=\"image\" src=\"https://github.com/sendbird/ecommerce-ai-chatbot/assets/104121286/27628078-b92d-433f-911e-c7e1b2f15c29\"\u003e\n\nThe `Welcome Message` is the first message displayed to users by the chatbot. Along with the `Welcome Message`, you can also set up `Suggested Replies` from the Dashboard.\n\nYou can find this setting under Chat \u003e AI Chatbot \u003e Manage bots \u003e Edit \u003e Bot settings \u003e Default messages \u003e Welcome message / Suggested replies.\n\n- Input example\n  \u003cimg width=\"1140\" alt=\"image\" src=\"https://github.com/sendbird/ecommerce-ai-chatbot/assets/104121286/41c088dc-f2ef-414c-93a0-742c1dc4f9bc\"\u003e\n\n## UI Components\n### CardView\nThe `data` in the response are displayed in a Card view. In the demo, information such as order items and their delivery status can be displayed in a card with an image, title, and description. Customization of the view can be done through `cardViewParamsCollectionBuilder` and `SBUCardViewParams`. The following codes show how to set the Card view of order status.\n\n[SBUUserMessageCell.swift](https://github.com/sendbird/ecommerce-ai-chatbot/blob/develop/Sources/View/Channel/MessageCell/SBUUserMessageCell.swift#L159)\n```swift\n// MARK: Card List\nif let cardListView = self.cardListView {\n    self.contentVStackView.removeArrangedSubview(cardListView)\n}\n\nlet functionResponse = json[\"function_calls\"][0]\n\nif functionResponse.type != .null {\n    let statusCode = functionResponse[\"status_code\"].intValue\n    let functionName = functionResponse[\"name\"].stringValue\n    let response = functionResponse[\"response_text\"]\n\n    if statusCode == 200 {\n        if functionName.contains(\"get_order_list\") {\n            customText = \"Here is your order list\"\n            SBUGlobalCustomParams.cardViewParamsCollectionBuilder = { messageData in\n                guard let json = try? JSON(parseJSON: messageData) else { return [] }\n\n                return json.arrayValue.compactMap { order in\n                    let deliveryStatus = order[\"status\"].stringValue\n                    var icon: String = \"\"\n\n                    switch deliveryStatus {\n                    case \"delivered\":\n                        icon = \"✅\"\n                    case \"delivering\":\n                        icon = \"🚚\"\n                    case \"preparing\":\n                        icon = \"⏳\"\n                    default:\n                        break\n                    }\n\n                    let titleWithIcon = icon.isEmpty ? \"Order #\\(order[\"id\"].stringValue)\" : \"\\(icon) Order #\\(order[\"id\"].stringValue)\"\n\n                    return SBUCardViewParams(\n                        imageURL: nil,\n                        title: titleWithIcon,\n                        subtitle: \"Your Order \\(deliveryStatus)\",\n                        description: \"Items:\" + ((order[\"items\"].arrayObject as? [String])?.joined(separator: \", \"))!,\n                        link: nil\n                    )\n                }\n            }\n            if let items = try?SBUGlobalCustomParams.cardViewParamsCollectionBuilder?(response.rawString()!){\n                self.addCardListView(with: items)\n            }\n        } else if functionName.contains(\"get_order_details\") {\n            customText = \"Here is your order details\"\n            SBUGlobalCustomParams.cardViewParamsCollectionBuilder = { messageData in\n                guard let json = try? JSON(parseJSON: messageData) else { return [] }\n\n                // Convert the single order object into a SBUCardViewParams object\n                let orderParams = SBUCardViewParams(\n                    imageURL: nil,\n                    title: \"Order #\\(json[\"id\"].stringValue) by \\(json[\"customer_name\"].stringValue)\",\n                    subtitle: \"- Status: \\(json[\"status\"].stringValue)\\n- Estimated Delivery Date: \\(json[\"estimatedDeliveryDate\"].stringValue)\",\n                    description: \"- Items: \" + ((json[\"items\"].arrayObject as? [String])?.joined(separator: \", \"))! + \"\\n- Total Price: $\\(json[\"purchasePrice\"].intValue)\",\n                    link: nil\n                )\n\n                // Return the SBUCardViewParams object inside an array\n                return [orderParams]\n            }\n            if let items = try?SBUGlobalCustomParams.cardViewParamsCollectionBuilder?(response.rawString()!){\n                self.addCardListView(with: items)\n            }\n        } else if functionName.contains(\"get_recommendation\") {\n            customText = \"Here are some recommended items for you\"\n            disableWebview = true\n            SBUGlobalCustomParams.cardViewParamsCollectionBuilder = { messageData in\n                guard let json = try? JSON(parseJSON: messageData) else { return [] }\n\n                return json.arrayValue.compactMap { item in\n                    return SBUCardViewParams(\n                            imageURL: item[\"image\"].stringValue,\n                            title: item[\"name\"].stringValue,\n                            subtitle: \"$\\(item[\"price\"].intValue)\",\n                            description: nil,\n                            link: nil\n                    )\n                }\n            }\n            if let items = try?SBUGlobalCustomParams.cardViewParamsCollectionBuilder?(response.rawString()!){\n                self.addCardListView(with: items)\n            }\n        }\n\n    }\n} else {\n    self.cardListView = nil\n}\n\n```\n\n### QuickReplyView\nThe following codes demonstrate how to set the view for Quick Replies. The values in `options` of `first_message_data.data` are used as Quick Replies.\n\n[SBUUserMessageCell.swift](https://github.com/sendbird/ecommerce-ai-chatbot/blob/develop/Sources/View/Channel/MessageCell/SBUUserMessageCell.swift#L150)\n```swift\n// MARK: Quick Reply        \nif let quickReplyView = self.quickReplyView {\n    quickReplyView.removeFromSuperview()\n    self.quickReplyView = nil\n}\n\nif let quickReplies = json[\"quick_replies\"].arrayObject as? [String], !quickReplies.isEmpty {\n    self.updateQuickReplyView(with: quickReplies)\n}\n```\n\n## Limitations\n`Tokens`\nThe maximum number of tokens allowed for `data` is 4027. Make sure that the settings information including the system message does not exceed the limit.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsendbird%2Fecommerce-ai-chatbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsendbird%2Fecommerce-ai-chatbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsendbird%2Fecommerce-ai-chatbot/lists"}