Search Unity

How to create WhatsApp stickers at runtime for iOS and Android

Discussion in 'Scripting' started by Rivven, Jan 22, 2020.

  1. Rivven

    Rivven

    Joined:
    Mar 7, 2015
    Posts:
    4
    I'm wondering if there's an asset out there in which you can create stickers for WhatsApp at runtime. I know this is possible within a native iOS and Android app (WhatsApp has provided an native example project for iOS and Android if I'm not mistaken) however I'm not sure how to implement this in unity.

    How would I go and create a link with the native libraries to be able to do this in Unity? (really inexperienced with native coding for iOS and Android in any form whatsoever)
    I tried looking it up and came across this: https://medium.com/@rolir00li/integrating-native-ios-code-into-unity-e844a6131c21
    Would this be the way to go or is there a somewhat easier track to follow?

    I hope this is at all possible.

    Thank you in advance.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,726
    I just glanced over this now and it looks like you could use their iOS and / or Android examples as a guideline to do it yourself. It appears like it would just be a series of network calls to establish authentication, package up the sticker along with some metadata and send it. It does NOT look like you need any native code, except if you wanted to get at your local camera photo roll, for instance. But if you had a texture in Unity, it seems like the rest is just networking.

    I would not classify it as a beginner programming task however. Anything networking is always a bit tricky when you've not done it. However, you would certainly learn a lot if you tried it!

    Alternatively, you might actually have some luck looking for someone who might have already done this. I didn't see anything directly for this on the Unity Asset Store, but looking at the
    sendToWhatsApp
    function in their code, it's pretty straightforward. It's just setting up all the auth, packaging it right, blasting it over the net, etc.
     
  3. Rivven

    Rivven

    Joined:
    Mar 7, 2015
    Posts:
    4
    Hi Kurt-Dekker,

    Thanks for your reply. You've set my mind at ease. I will look into this straight away and post my findings. I've never done anything like this before but it would certainly be a challenge and a good learning experience!
    Thanks again!
     
    Kurt-Dekker likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,726
    Glad you're gonna give this a shot. If you're new to networking under Unity, just use the good old UnityWebRequest, as I imagine that can do what you need. Try just getting public websites first, to get a feel for async programming.

    The trickiest part is probably going to be getting the authentication right for WhatsApp but the good news is there is at least one other person on the planet using this, and you have the native ios/android source codes.
     
  5. evgeny44mikhalev

    evgeny44mikhalev

    Joined:
    Sep 4, 2018
    Posts:
    9
    Hey Rivven, did you manage it?
     
  6. ugur

    ugur

    Joined:
    Jun 3, 2008
    Posts:
    692
    i implemented this before, some pointers:
    -you will need some native side code no matter how you do it (as there aren't apis for all of the aspects in Unity api).
    I'll give an overview for iOS for whatsapp:
    -a json string is passed to the system pasteboard and whatsapp triggered via url scheme to use it.
    Now this json string contains the whole stickerpack data, including the tray image which is a png encoded in base64 and a sticker image for each sticker in webp format encoded as base64, next to all the other meta data for the stickers and sticker pack.
    so you need to do the transcoding to webp and base64 on unity or native side and then the push to pasteboard and whatsapp on native side.
    (on android some aspects are the same, some others again quite different)
    while the native iOS and Android projects provided by whatsapp are nice as a starting point for native apps, i found them not that well integrateable quickly into Unity projects, so i used a plugin for the webp conversion and do the base64 encoding and whole json generation on unity side and then push the whole json to native side where i push it to pasteboard/whatsapp.
    Works well, but yes, these sticker pack integrations for the different message apps and keyboards are actually time intensive work as each has different requirements and implementations for iOS and Android and you have to do builds and test on device frequently in development iterations, so while totally doable, be prepared for some time investment there.
     
    Kurt-Dekker likes this.
  7. adityaspt

    adityaspt

    Joined:
    Mar 22, 2020
    Posts:
    6
    Hey ugur, can you share your work on github, so that i would be a help to us.