أندرويد (Kotlin)
التثبيت
dependencies {
implementation("com.heysada:sanad:0.1.0")
}
شرح الاستخدام أدناه بالإنجليزية، كما يظهر في سجل الحزمة، والشيفرة نفسها في كل لغة.
In-app support as a messenger, for native apps. The user opens it from your Help button or the launcher. They see your team’s welcome and how soon it replies, their conversations with the team as they happen, and your help articles. They write to the team from the contact form, with a screenshot of the screen they were on if they want, and every reply arrives live.
The web (Web) and Flutter (Flutter) SDKs behave the
same way. All three speak sanad-support’s /sdk/v1. This one is Kotlin Multiplatform: the same
Compose screens on Android (minSdk 26) and iOS (the Swift package in the repository, which
presents them), built on the shared KMP core (transport, offline
queue, store, install id) and the shared Compose renderer for the app’s design.
Use it (Android)
class App : Application() {
override fun onCreate() {
super.onCreate()
AppSupport.configure(this, AppSupportOptions(
appKey = "pk_…", // the panel → Support apps → keys (publishable)
apiUrl = "https://support.example.com", // where sanad-support serves /sdk/v1
appVersion = BuildConfig.VERSION_NAME,
))
}
}
// your own help button, in any Activity:
helpButton.setOnClickListener { AppSupport.open(this) }
// or the launcher, in a full-screen Box of your Compose layout:
Box(Modifier.fillMaxSize()) {
YourScreen()
SupportLauncher(bottom = 80.dp) // above your bottom bar
}
open(activity)shows the messenger’s home;openContact(activity)the contact form;openConversation(activity, id)one conversation (from a push about a reply, say);openArticle(activity, id)one help article. A second tap while it opens does nothing;close()closes it.- The launcher sits at the screen’s end side (right in English, left in Arabic) above
bottom, in yourcolourif you give one, with the number of replies the user hasn’t read.AppSupport.unread()is the same count for a badge of your own. - Mark what must never leave the device:
Modifier.supportMask()in Compose,AppSupport.mask(view)for a View (card numbers, balances, personal details). Password fields (a passwordEditText, or a Compose field withPasswordVisualTransformation/SecureTextField) and WebViews, SurfaceViews and TextureViews are blacked out too, before the user sees the preview. - The language follows
AppSupportOptions.language, then the app’s locale (aroren), then the app’s first language. Arabic is fully right to left. userIdis sent asuser_idwith a message and the conversations list.userToken: the signed-in user’s token from the platform’s identify (X-User-Token): with it, the user’s conversations follow them to every device. Not yet: until sanad-support runs on the end-user token verifier (chassis 0.38.0), a sent token is refused (401) and the conversations, home and badge stay empty; leaveuserTokenout until this note is gone.- The library declares
INTERNET, and itsSupportActivitymerges into your manifest.
Ways in: shake, screenshot, the floating launcher
Each one is off until the host switches it on:
AppSupport.configure(this, AppSupportOptions(
appKey = "pk_…", apiUrl = "https://support.example.com",
invocations = SupportInvocations(shake = true, shakeAction = ShakeAction.Chooser, screenshot = true, launcher = true),
))
- Shake. Android reads
SensorManager’s accelerometer, and iOS reads CoreMotion’s (an SDK can’t take the host’s responder chain, somotionEndedstays the host’s). It only listens while the app is in front.ShakeDetectorholds the rule: two readings over 2.7 g within 500 ms, then a 1.5 s cooldown. A shake opens a chooser (Report a problem / Get help) or, withShakeAction.Contact, the form straight away. - Screenshot taken. Android 14 and later use
Activity.ScreenCaptureCallback, and the SDK’s manifest declares the normalDETECT_SCREEN_CAPTUREpermission. Android 13 and earlier have no such event, so there is no prompt there. iOS usesuserDidTakeScreenshotNotification. A prompt that doesn’t block the screen asks “Need help with what’s on screen?” and goes after 6 s. The system’s image is never read. The SDK takes its own capture right away, masked like every other. - Floating launcher. On Android it goes on every
ComponentActivity, and on iOS over the key window. The user can drag it, and when they let go it snaps to the nearer side edge (logical, so the end side is the left in Arabic). It shows the unread badge. UseAppSupport.hideLauncher()/showLauncher()(SanadAppleon iOS). The launcher and the prompt are hidden while a screenshot is taken.
Opening from a failure: topic and attributes
AppSupport.openContact(
activity,
topic = "payment_failed",
attributes = mapOf("order_id" to order.id, "error_code" to e.code, "amount" to 12.5),
message = "My payment didn't go through",
)
open(...) takes the same three. The team sees the topic and attributes with the conversation,
and they are not sent to the corpus. The user sees them listed under the form. Keys are
snake_case (at most 40), values are flat (text up to 256, a number, a Boolean), and at most 20
are sent. Anything else is left out with a log line.
What it does, and what it never does
- It never opens itself and never throws into your app. Problems go to the log (tag
support). - Live, not polled. While the messenger or the launcher is shown, one stream
(
GET /sdk/v1/events) brings the team’s replies, typing, read marks and the unread count. It reconnects by itself with the last event id it saw (Last-Event-ID), so nothing is missed, backs off while the service can’t be reached, and stops for good on a refusal (a bad key). - Images both ways. The user sends a PNG or JPEG from the system photo picker (no permission); the team’s images show in the thread from signed links that expire.
- One still image of your app, for the contact form, taken the moment Support opens and before
anything is drawn (Android:
PixelCopyof the activity’s window; iOS: the key window). It needs no permission and has no system prompt. It is at most 2× and 4096 px on a side. The user can hide parts (burned into the pixels), remove it, or attach it (theaskmode). What the preview shows is exactly what is uploaded. It lives in memory only and is never written to disk. - Offline, the contact form is the one sanad-support last filled for this app and language,
with the design the device last read, and what is sent waits in the core’s queue: text only (the
screenshot never), at most 5 messages, for up to 3 days. It is sent at the next
configure()oropen(), or when the app comes back to the foreground. - The help assistant answers only from your articles and names the ones it used. When it can’t answer, “Didn’t help?” moves the user to the form with the conversation attached.
- Only the allowlisted context is sent with a message: app version, build, OS name and major version, phone or tablet, and the language. The form lists it under the message.
- The app’s design is the one source of the look (ADR 031):
every screen takes the design’s colours (
designColours, light or dark as the device is), and the contact form is the design’s view drawn with the shared renderer.
Build and check
./check.sh is the gate: ktlint and detekt, every test on the JVM (the wire against
services/sanad-support/openapi.json, the live stream, the messenger’s state, the contact form’s
design) and the core tests on the iOS simulator, the Android library, the example host with
Android lint, and the iOS framework. example/ is a wallet-like host for trying it on a phone:
./gradlew :example:installRelease -PapiUrl=http://127.0.0.1:18191 -PappKey=pk_… with
adb reverse tcp:18191 tcp:18191. e2e/ui.py drives it (the screens set testTagsAsResourceId,
so the support-* tags are resource ids).