chat-sdk-android icon indicating copy to clipboard operation
chat-sdk-android copied to clipboard

How to create custom module.

Open onepas opened this issue 9 years ago • 7 comments

Hi, First thank for very nice chat sdk product. I can see many modules at http://chatsdk.co/modules-2/, but now I want to write own module, so how can I start? I can't find any documents about how to write custom module for ChatSDK. (both Android and IOS)

Thanks.

onepas avatar Mar 06 '17 03:03 onepas

Hi @onepas,

What kind of functionality were you looking to develop? I can then give you some pointers on how to go about developing new modules,

Simon

simonsmiley64 avatar Mar 06 '17 04:03 simonsmiley64

Hi @simonsmiley64 Thank for your quick reply. I want to intergrate ChatSDK with eCommerce app, so I want some custom message type, for example: https://fast-company-res.cloudinary.com/image/upload/w_596/fc/3052632-inline-s-3-tumblr-for-online-shops-tictail-releases-in-app-messaging.jpg

Some messages type is:

  • product information
  • order confirm
  • order status
  • shiping status/progress

Thank you.

onepas avatar Mar 06 '17 05:03 onepas

Hi @onepas,

Firstly all of those message types would be possible. Depending on the information you wanted to send with them would determine their complexity but creating new message type isn't too difficult.

You therefore have two option:

Develop them yourself The Chat SDK is pretty logical meaning each message type has been developed the same way. Much of creating new message types would be copying and then modifying the existing code. Once again this would depend on the information you want to send. I can give you some guidance on how to create this but we wouldn't be able to support the final code. We can troubleshoot obvious issues but not your entirely new code.

We can do some development for you As we wrote the code we know it inside out. We could put together a quote to look at how long it would take to create some new message types. This would be substantially quicker than you coding it yourself and we fully support all projects we complete.

Let me know which you think would be best for you. Also if you can provide some more specific information on the data being sent with each message type (image, text, video, sound etc), I can give you an idea of how easy each type would be to create.

Simon

simonsmiley64 avatar Mar 06 '17 09:03 simonsmiley64

Hi @simonsmiley64 Thank for your information, I will try to develop by myself first that because I need a prototype of app. So, can you share me a simple project module template?

Thank you.

onepas avatar Mar 07 '17 01:03 onepas

Hello @onepas ,

The add-ons are offered as modules, but they are not quite plug ins. The messaging ones in particular are coupled with the existing messaging code in the current version of the SDK. So we do not have templates available, but instead merge the features in.

We are working on improving the modularity of these add-ons, and if you have any feedback we are more than happy to listen.

-- Kyle

kykrueger avatar Mar 09 '17 17:03 kykrueger

Closing this issue since we are not able to provide templates given the architecture. Interfaces for development will however be available in later versions of the SDK.

kykrueger avatar Mar 11 '17 14:03 kykrueger

Hi @onepas

I will write a tutorial on how to make a custom module but in the meantime here are some pointers for iOS.

Creating a pod

  1. You will need to create a new podspec for your module. You can look at the Backendless module as a guide to do this. The only difference is that the backendless module is a subspec whereas you will create a full podspec for your module.

  2. You should import your pod to the project by adding it as a development pod to the Podfile. Once you run pod install, your code will be added to the Chat SDK.

Making a custom message type

Making a custom cell is very straightforward. You need to make a custom handler and a custom message cell.

When you make a message cell you can look at the image or location message cell for guidance. You should inherit from BMessageCell and implement BMessageDelegate.

In the setMessage function, you can perform any customization you need. This usually involves interpreting the message payload to setup the cell. For example, if you sent an image, you would get the image URL from the payload and use it to set the image view that was associated with the cell.

You should then add your message cell type to the customCellTypes function in your Chat View Controller.

The handler class will contain a custom sendMessageWith... function which will perform all the necessary steps to correctly set the message payload and upload files if necessary. Again you can look at the image or location message handlers for examples.

Your handler should have a protocol which will be added to the Chat SDK Core module and a property that will be added to the Default Network Adapter. Again, I'd advise looking at the image message handler.

If you are modifying code from any of the core pods that relies on your module, you should wrap them using an ifdef statement.

#ifdef ChatSDKYourModuleNameModule

Your pod should have a main header file called YourModuleName.h and this will contain all the header imports for your module. In this file you should define a variable called ChatSDKYourModuleNameModule. You can then add the following code to the BModules.h file.

#if __has_include(<YourPodName/YourModuleName.h>)
#import <YourPodName/YourModuleName.h>
#endif

This will cause your pod to be imported if it's installed.

Adding your pod to the main repository

You should do this on a separate branched called contrib_module_your_module_name and when it's finished, you should submit a pull request to have it added to the main codebase.

bensmiley avatar Mar 14 '17 01:03 bensmiley