@codeimplants/support
v1.0.0
Published
Smart support logic layer for error handling and user assistance
Maintainers
Readme
@codeimplants/support
Smart support logic layer for error handling and user assistance across all platforms
Overview
@codeimplants/support is a comprehensive support package that handles the logic of how users contact your organization based on their platform and error context. It provides seamless integration with WhatsApp, Email, and Phone services with automatic error context formatting.
Features
- ✅ Cross-Platform: Works on iOS, Android, Web (React Native Web), Expo, and bare React Native
- ✅ Smart Deep Linking: Platform-specific URL schemes (whatsapp://, mailto:, tel:)
- ✅ Auto Error Context: Automatically formats error details in support messages
- ✅ Type-Safe: Full TypeScript support with comprehensive types
- ✅ Zero Config: Works out of the box with sensible defaults
- ✅ Customizable: Override templates, messages, and platform-specific behavior
Installation
npm install @codeimplants/support
# or
yarn add @codeimplants/support
# or
pnpm add @codeimplants/supportPeer Dependencies
{
"react": ">=18.0.0",
"react-native": ">=0.70.0"
}Quick Start
1. Wrap your app with SupportProvider
import { SupportProvider } from '@codeimplants/support';
const supportConfig = {
whatsapp: {
number: '919876543210', // Country code + number (no + or spaces)
messageTemplate: 'Hello, I need help with...',
},
email: {
address: '[email protected]',
subjectTemplate: 'Support Request',
},
phone: {
number: '+919876543210',
},
};
function App() {
return (
<SupportProvider config={supportConfig}>
<YourApp />
</SupportProvider>
);
}2. Use the useSupport hook
import { useSupport } from '@codeimplants/support';
function ErrorScreen() {
const { openWhatsApp, sendEmail, makeCall, isMethodAvailable } = useSupport({
errorMessage: 'Failed to load user profile',
errorCode: '500',
screenName: 'ProfileScreen',
timestamp: new Date().toISOString(),
appVersion: '1.0.0',
platform: 'ios',
os: 'iOS 17.0',
});
return (
<View>
<Button onPress={() => openWhatsApp()}>
Contact via WhatsApp
</Button>
<Button onPress={() => sendEmail()}>
Send Email
</Button>
{isMethodAvailable('phone') && (
<Button onPress={() => makeCall()}>
Call Support
</Button>
)}
</View>
);
}API Reference
SupportProvider
React Context Provider that makes support configuration available throughout your app.
Props:
config: SupportConfig- Support configuration object
useSupport(errorContext?)
Primary hook for interacting with support services.
Parameters:
errorContext?: ErrorContext- Optional error context to include in support messages
Returns:
{
openWhatsApp: (customMessage?: string) => Promise<SupportActionResult>;
sendEmail: (customSubject?: string, customBody?: string) => Promise<SupportActionResult>;
makeCall: () => Promise<SupportActionResult>;
isMethodAvailable: (method: 'whatsapp' | 'email' | 'phone') => boolean;
config: SupportConfig;
}Platform Utilities
import { isWeb, isIOS, isAndroid, getNormalizedPlatform } from '@codeimplants/support';
// Check platform
if (isWeb()) {
// Web-specific logic
}
// Get normalized platform ('web' | 'ios' | 'android')
const platform = getNormalizedPlatform();Platform-Specific Configuration
Override configuration for specific platforms:
const config = {
whatsapp: { number: '919876543210' },
email: { address: '[email protected]' },
platformOverrides: {
web: {
// Web users get different email
email: { address: '[email protected]' },
},
ios: {
// iOS users can call directly
phone: { number: '+919876543210' },
},
},
};Error Context Auto-Formatting
When you provide an ErrorContext, it's automatically formatted into support messages:
WhatsApp Message:
Hello, I need help with an issue.
--- Error Details ---
Error: Failed to load user profile
Code: 500
Screen: ProfileScreen
Time: 2024-02-11T16:30:00.000Z
App Version: 1.0.0
Platform: iosEmail Body:
Hello,
I need assistance with an issue.
--- Error Details ---
Error: Failed to load user profile
Error Code: 500
Screen: ProfileScreen
Timestamp: 2024-02-11T16:30:00.000Z
App Version: 1.0.0
Platform: ios
OS: iOS 17.0
Please describe your issue:Platform Compatibility
React Native (Expo)
✅ Works out of the box
React Native (Bare)
✅ Works out of the box
React Native Web
✅ Automatically detects web platform and uses https://wa.me/ for WhatsApp
iOS
✅ Uses whatsapp://, mailto:, tel: URL schemes
Android
✅ Uses whatsapp://, mailto:, tel: URL schemes
TypeScript Support
Full TypeScript support with exported types:
import type {
SupportConfig,
ErrorContext,
SupportMethod,
SupportActionResult,
} from '@codeimplants/support';License
MIT
Contributing
Contributions are welcome! Please open an issue or PR.
