Skip to content

Koredotcom/react-native-botsdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– React Native Kore Bot SDK - Sample App

NPM Version Platform License TypeScript

Complete sample implementation demonstrating Kore.ai chatbot integration with selective feature loading

🎯 What's This?

This sample app showcases how to integrate the Kore Bot SDK with selective dependency installation, allowing you to choose only the features you need and save significant bundle size.


πŸ“‹ Table of Contents


✨ Features

🎯 Core Features

  • πŸ€– Complete chatbot UI components
  • πŸ’¬ Rich messaging templates
  • 🎨 Fully customizable themes
  • πŸ“± Cross-platform (iOS & Android)
  • πŸ”§ Full TypeScript support

πŸš€ Advanced Features

  • 🎡 Voice recognition & TTS
  • πŸ“ File upload/download
  • πŸ“Š Charts & data visualization
  • πŸ”„ Real-time messaging
  • 🎭 Custom template injection

πŸš€ Quick Start

Get up and running in minutes:

import React from 'react';
import { View } from 'react-native';
import KoreChat, { BotConfigModel } from 'rn-kore-bot-sdk-v77';

const App = () => {
  const botConfig: BotConfigModel = {
    botId: 'your-bot-id',
    chatBotName: 'Assistant',
    serverUrl: 'https://your.server.url',
    brandingAPIUrl: 'https://your.branding.url',
  };

  return (
    <View style={{ flex: 1 }}>
      <KoreChat
        botConfig={botConfig}
        onListItemClick={(item) => console.log('πŸ“‹ Item clicked:', item)}
        onHeaderActionsClick={(action) => console.log('⚑ Action:', action)}
      />
    </View>
  );
};

export default App;

πŸ“¦ Sample App Installation

Step 1: Clone & Install Base

git clone <repository-url>
cd SampleApp
npm install

Step 2: Choose Your Features

This sample app demonstrates 3 different installation approaches:

🎯 Installation Options

Option A: πŸš€ Minimal Chat (~380KB saved)

Perfect for basic chat functionality

# Only install required dependencies
npm install \
  "@react-native-async-storage/async-storage@^2.2.0" \
  "@react-native-community/netinfo@^11.4.1" \
  "@react-navigation/native@^7.1.14" \
  "@react-navigation/stack@^7.4.2" \
  "react-native-gesture-handler@^2.27.2" \
  "react-native-safe-area-context@^5.4.1" \
  "react-native-screens@^4.13.1"

Features Available:

  • βœ… Basic chat interface
  • βœ… Text messaging
  • βœ… Simple templates
  • ❌ Voice features (buttons hidden)
  • ❌ Audio playback (silent mode)
  • ❌ Video content (static thumbnails)

Option B: 🎀 Chat + Voice (~300KB saved)

Adds voice recognition and TTS

# Install minimal + voice features
npm install \
  "@react-native-voice/voice@^3.2.4" \
  "react-native-tts@^4.1.1" \
  "react-native-permissions@^5.4.1"

Additional Features:

  • βœ… Voice-to-text input
  • βœ… Text-to-speech playback
  • βœ… Microphone permissions handling

Option C: πŸ“± Full Experience (Complete features)

Install all optional dependencies

# Complete feature set
npm install \
  "@react-native-picker/picker@^2.11.0" \
  "@react-native-voice/voice@^3.2.4" \
  "@react-native-community/datetimepicker@^8.4.4" \
  "react-native-communications@^2.2.1" \
  "react-native-document-picker@^9.3.1" \
  "react-native-fast-image@^8.6.3" \
  "react-native-image-picker@^8.2.1" \
  "react-native-parsed-text@^0.0.22" \
  "react-native-popover-view@^6.1.0" \
  "react-native-reanimated-carousel@^4.0.3" \
  "react-native-sound@^0.12.0" \
  "react-native-tts@^4.1.1" \
  "react-native-video@^6.16.1"

All Features:

  • βœ… Everything from Options A & B
  • βœ… Rich media support (images, videos, audio)
  • βœ… Advanced templates (carousels, pickers)
  • βœ… File attachments
  • βœ… Enhanced UI components

πŸ“Š Feature Comparison

Feature Minimal Voice Full
Bundle Size Base Base + 80KB Base + 380KB
Savings 380KB 300KB 0KB
Chat Interface βœ… βœ… βœ…
Voice Input ❌ βœ… βœ…
Audio Playback ❌ βœ… βœ…
Video Messages πŸ“· Thumbnail πŸ“· Thumbnail ▢️ Full Player
File Uploads ❌ ❌ βœ…
Rich Templates Basic Basic Advanced
Phone/Email Actions Basic Basic Native

Step 3: Platform Setup

🍎 iOS Setup
cd ios && pod install && cd ..

Add to ios/YourProject/Info.plist:

<key>NSMicrophoneUsageDescription</key>
<string>This app needs microphone access for voice messages</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>This app uses speech recognition for voice-to-text</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs photo library access for attachments</string>
<key>NSCameraUsageDescription</key>
<string>This app needs camera access for photos</string>
πŸ€– Android Setup

Add to android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />

🎯 Basic Usage

Simple Integration

import React from 'react';
import { SafeAreaView, StatusBar } from 'react-native';
import KoreChat, { BotConfigModel, ThemeProvider } from 'rn-kore-bot-sdk-v77';

const App = () => {
  const botConfig: BotConfigModel = {
    botId: 'st-12345678-1234-1234-1234-123456789012',
    chatBotName: 'My Assistant',
    serverUrl: 'https://bots.kore.ai',
    brandingAPIUrl: 'https://bots.kore.ai',
    customerId: 'your-customer-id',
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret',
    identity: 'your-user-identity',
    isAnonymous: false,
    isPlatform: true,
  };

  return (
    <SafeAreaView style={{ flex: 1, backgroundColor: '#f5f5f5' }}>
      <StatusBar barStyle="dark-content" backgroundColor="#ffffff" />
      <KoreChat
        botConfig={botConfig}
        onListItemClick={handleListItemClick}
        onHeaderActionsClick={handleHeaderAction}
      />
    </SafeAreaView>
  );
};

const handleListItemClick = (item: any) => {
  console.log('πŸ“‹ List item selected:', item);
};

const handleHeaderAction = (action: any) => {
  console.log('⚑ Header action triggered:', action);
};

export default App;

🎨 Customization

Theme Customization

import { ThemeProvider } from 'rn-kore-bot-sdk-v77';

const customTheme = {
  primaryColor: '#007AFF',
  secondaryColor: '#5856D6',
  backgroundColor: '#F2F2F7',
  textColor: '#000000',
  borderColor: '#C7C7CC',
  // Add more theme properties
};

const App = () => (
  <ThemeProvider theme={customTheme}>
    <KoreChat botConfig={botConfig} />
  </ThemeProvider>
);

Custom Templates

import { CustomTemplate } from 'rn-kore-bot-sdk-v77';

const MyCustomButton = new CustomTemplate({
  templateType: 'custom-button',
  render: (data, onAction) => (
    <TouchableOpacity
      style={styles.customButton}
      onPress={() => onAction(data.action)}
    >
      <Text>{data.title}</Text>
    </TouchableOpacity>
  ),
});

<KoreChat
  botConfig={botConfig}
  templateInjection={new Map([
    ['custom-button', MyCustomButton]
  ])}
/>

πŸ“š API Reference

KoreChat Component Props

Prop Type Required Description
botConfig BotConfigModel βœ… Bot configuration object
onListItemClick (item: any) => void ❌ Callback for list item interactions
onHeaderActionsClick (action: any) => void ❌ Callback for header action buttons
templateInjection Map<string, CustomTemplate> ❌ Custom template injection map
themeConfig ThemeConfig ❌ Custom theme configuration

BotConfigModel Interface

interface BotConfigModel {
  // Required fields
  botId: string;              // Bot identifier
  chatBotName: string;        // Display name for the bot
  serverUrl: string;          // Server URL (without trailing slash)
  brandingAPIUrl: string;     // Branding API URL (without trailing slash)
  
  // Authentication
  customerId?: string;        // Customer identifier
  clientId?: string;          // OAuth client ID
  clientSecret?: string;      // OAuth client secret
  identity?: string;          // User identity
  
  // Configuration
  isAnonymous?: boolean;      // Anonymous user mode
  isPlatform?: boolean;       // Platform integration mode
  enableHistory?: boolean;    // Chat history feature
  allowAttachments?: boolean; // File attachment feature
}

πŸ› οΈ Advanced Configuration

Conditional Native Module Loading

The library implements graceful degradation for native modules:

// βœ… Automatic fallback when modules are unavailable
// ⚠️ Logs appropriate warnings for missing features
// πŸ”„ Continues functioning with reduced capabilities

Error Handling

import { BotException } from 'rn-kore-bot-sdk-v77';

try {
  // Bot operations
} catch (error) {
  if (error instanceof BotException) {
    console.log('Bot error:', error.message);
  }
}

πŸ” Permissions Setup

🎀 Voice Features

The SDK includes voice recognition and text-to-speech capabilities:

Permission Status Indicators

Status Description Action Required
βœ… Granted Voice features available None
⚠️ Denied Voice button hidden Check app settings
πŸ”„ Not Requested Will prompt on first use None

Troubleshooting Voice Issues

πŸ”§ Common Voice Problems

Problem: "Microphone permission denied" Solution:

  1. Check Info.plist/AndroidManifest.xml permissions
  2. Reset app permissions in device settings
  3. Reinstall app to re-trigger permission prompts

Problem: Voice button not appearing Solution:

  1. Verify @react-native-voice/voice installation
  2. Check native module linking
  3. Rebuild project after adding permissions

πŸ“± Console Logs for Debugging

// βœ… Success logs
"Voice module loaded successfully"
"Microphone permission granted"

// ⚠️ Warning logs  
"Voice module not available"
"Microphone permission denied"
"Permissions module not available"

πŸ“± Testing Different Configurations

πŸ§ͺ How to Test Each Configuration

  1. Start with Minimal Installation:
# Install only required dependencies
npm install # (just the minimal set)
npx react-native run-ios
  1. Test Lazy Loading Behavior:
# Try using features without dependencies installed
# - Tap voice button β†’ See "Voice not available" message
# - Play audio β†’ See silent mode
# - Open video β†’ See static thumbnail
  1. Add Features Incrementally:
# Add voice features
npm install @react-native-voice/voice react-native-tts
npx react-native run-ios

# Now voice buttons should appear and work

πŸ” Debugging Lazy Loading

Check Console Logs:

// Look for these messages in your console:
"LazySound: react-native-sound not installed, using fallback"
"LazyVoice: Voice module loaded successfully"  
"LazyVideo: Loading video player..."

Visual Indicators:

  • πŸ”„ Loading spinners when modules are loading
  • ⚠️ Warning messages for missing dependencies
  • βœ… Success indicators when features are ready

πŸ“‹ Key Sample Files

  • src/config/BotConfig.tsx - Configuration setup
  • src/screens/Home/index.tsx - Integration example
  • src/screens/TestFeatures.tsx - Feature testing screen
  • src/components/LazyComponents/ - Lazy loading examples

🎯 Sample Application

Run the complete sample:

cd SampleApp
npm install
npx react-native run-ios    # or run-android

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Setup

git clone https://github.com/your-repo/react-native-kore-bot-sdk.git
cd react-native-kore-bot-sdk
npm install

πŸš€ Quick Commands

npm run test          # Run tests
npm run lint          # Lint code
npm run build         # Build library
npm run example       # Run example app

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ’¬ Support

Need Help?

GitHub Issues Documentation Stack Overflow

Found a bug? Open an issue Have a question? Start a discussion Need enterprise support? Contact Kore.ai


🎯 Quick Start Guide

  1. Choose your approach from the 3 installation options above
  2. Install dependencies for your chosen features
  3. Run the app: npx react-native run-ios
  4. Test lazy loading by trying features without dependencies
  5. Add more features incrementally as needed

πŸ’‘ Pro Tips

  • Start minimal and add features as you need them
  • Check console logs to see lazy loading in action
  • Test on device for realistic bundle size impact
  • Use fallback components to handle missing dependencies gracefully

Made with ❀️ by the Kore.ai Team

Star this repo

About

Kore BOT SDK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 8