usedesk

Creator: coderz1093

Last updated:

0 purchases

usedesk Image
usedesk Images

Languages

Categories

Add to Cart

Description:

usedesk

usedesk #
Pure dart SDK implementation of usedesk.com service
Now added only UsedeskChat sdk

Getting Started #
In Example dir fully flutter chat integration with package flutter_chat_ui
Integrate anywhere by steps:

Need implement token storage, example with shared_preferences:

import 'package:shared_preferences/shared_preferences.dart';
import 'package:usedesk/usedesk.dart';

class SharedPreferencesUsedeskChatStorage extends UsedeskChatStorageProvider {
SharedPreferencesUsedeskChatStorage(this.prefs);
final SharedPreferences prefs;

@override
Future<String?> getToken() async {
return prefs.getString('token');
}

@override
Future<void> setToken(String token) {
return prefs.setString('token', token);
}

@override
Future<void> clearToken() {
return prefs.remove('token');
}
}
copied to clipboard

Initialize chat

final usedeskChat = await UsedeskChat.init(
/* Required */
storage: SharedPreferencesUsedeskChatStorage(prefs),
companyId: companyId,

/* Optional */
channelId: channelId,
apiConfig: const ChatApiConfiguration(
urlChat: 'https://pubsubsec.usedesk.ru',
urlOfflineForm: 'https://secure.usedesk.ru/',
urlToSendFile: 'https://secure.usedesk.ru/uapi/v1/send_file',
),
);
copied to clipboard

Identify client / pass additional data

usedeskChat
..identify = IdentifyConfiguration(
/* All params optional */
name: 'Serge Shkurko',
email: '[email protected]',
phoneNumber: 88005553535,
additionalId: 'uuid_in_my_system',
)
..additionalFields = {
'99999': 'v$appVersion:$appBuildNumber'
};
copied to clipboard

Subscribe on messages stream

usedeskChat.messagesStream.listen((List<MessageBase> message) {
MessageBase message = message.first;

final isMyMessage = message is MessageFromClient;

// Work with different messages
if (message is MessageTextBase) {
print(message.text);
} else if (message is MessageImageBase) {
print(message.file);
} else if (message is MessageFileBase) {
print(message.file);
}
});


copied to clipboard

Control connection

usedeskChat.connect(); // for receiving usedesk messages from socket

usedeskChat.disconnect(); // dismiss connection
copied to clipboard

Send message

// Text
usedeskChat.sendText('My cool message');

// File
usedeskChat.sendFile('My_cool_image.jpg', fileBytes);
copied to clipboard
Contributing #
Rebuild code generation tools
# One time run
dart pub run build_runner build --delete-conflicting-outputs

# Watching of file changes
dart pub run build_runner watch --delete-conflicting-outputs
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.