5

I'm trying to develop an app for KaiOS where I want to share text messages with WhatsApp.

I tried with deep-links like:

  • app://whatsapp/send
  • whatsapp://send

Both didn't work.

Does anyone know how share content with WhatsApp?

hc_dev
  • 8,389
  • 1
  • 26
  • 38
julient-monisnap
  • 774
  • 2
  • 8
  • 25

2 Answers2

4

You need to use the Web Activities API.

Activities defined for WhatsApp

There are two main activities exposed from WhatsApp:

  • share
  • view

See WhatsApp's manifest.webapp:

  "activities": {
    "share": {
      "href": "/notification.html",
      "filters": {
        "type": [
          "video/*",
          "image/*",
          "text/vcard",
          "text/plain"
        ]
      }
    },
    "view": {
      "href": "/notification.html",
      "filters": {
        "type": "url",
        "url": {
          "required": true,
          "pattern": "^https://(?:chat\\.whatsapp\\.com/(?:invite/)?[0-9A-Za-z]+|wa\\.me/[0-9]+(?:\\?text=.*)?)$",
          "patternFlags": "i",
          "regexp": "^https://(?:chat\\.whatsapp\\.com/(?:invite/)?[0-9A-Za-z]+|wa\\.me/[0-9]+(?:\\?text=.*)?)$"
        }
      }
    },
  }

Use activities to share

To share a text message using WhatsApp, you could instantiate MozActivity using the pre-defined activity names.

Something like this should work either from an app or web context.

var pick = new MozActivity({
  name: "share",
  data: {
    type: "text/plain",
    blobs: [ "This is a message to share via WhatsApp" ]
  }
});
hc_dev
  • 8,389
  • 1
  • 26
  • 38
Tom
  • 6,947
  • 7
  • 46
  • 76
  • Thank you for the interest for my question and answer. I did managed to do it quite recently and I've just posted the way to do it for the community :) – julient-monisnap Feb 11 '21 at 08:28
  • I like the re-engineering approach of your elaborate answer. So I suggested an edit to improve structure. Hope you don't mind. – hc_dev Apr 07 '21 at 19:07
1

I've finally managed to send a text message thanks to KaiOS and Whatsapp teams. This is the way to do it :


const phoneNumber = "0123456789"
const urlEncodedMessage = "SentFromKaios"

const sendTextMessageActivity = new MozActivity({
  name: "view",
  data: {
    type: "url",
    url: `https://wa.me/${phoneNumber}?text=${urlEncodedMessage}`
  }
})
julient-monisnap
  • 774
  • 2
  • 8
  • 25
  • The URL looks like the text-message is sent over the internet to Whatsapp public API (https://api.whatsapp.com/). I think you should __mention this "work-arround" in your answer__, because usually sharing via Whatsapp means to communicate with the local Whatsapp client via URI-schemes like `whatsapp:`. – hc_dev Apr 07 '21 at 18:09