{"_id":"@axis-llc/axis-gupshup-whatsapp","_rev":"1-74513b1492b701208af19293c3fb8ff5","name":"@axis-llc/axis-gupshup-whatsapp","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.2":{"name":"@axis-llc/axis-gupshup-whatsapp","version":"1.0.2","description":"Library to wrap GupShup WhatsApp APIs(v2) for messages and user opt-ins","main":"dist/gupshup","typings":"dist/gupshup","scripts":{"clean":"rm -rf dist && mkdir dist","cp-ts":"cp lib/gupshup.d.ts dist/","build:commonjs":"tsc","build":"npm run clean && npm run build:commonjs && npm run cp-ts","debug":"node examples/index.js","test":"npm run build && mocha --require babel-register --recursive --full-trace"},"author":{"name":"Axis Africa"},"license":"MIT","private":false,"repository":{"type":"git","url":"git+https://github.com/axis-llc/axis-gupshup-whatsapp.git"},"keywords":["gupshup","whatsapp-api","messaging-api","messaging","whatsapp"],"devDependencies":{"@types/node":"^14.14.21","babel-cli":"^6.26.0","babel-preset-es2015":"^6.24.1","babel-preset-stage-0":"^6.24.1","babel-register":"^6.26.0","chai":"^4.2.0","mocha":"^8.2.1","typescript":"^4.1.3"},"dependencies":{"axios":"^0.21.1","querystring":"^0.2.0"},"gitHead":"49e93c5c083e8aa6f6d7db471fd469b4d198e352","bugs":{"url":"https://github.com/axis-llc/axis-gupshup-whatsapp/issues"},"homepage":"https://github.com/axis-llc/axis-gupshup-whatsapp#readme","_id":"@axis-llc/axis-gupshup-whatsapp@1.0.2","_nodeVersion":"14.18.1","_npmVersion":"6.14.15","dist":{"integrity":"sha512-LKI4yBQyjHfoaSE6D+TfkpU3lA8L5qnIKYwjnmSeg3Bb9S9Llww7K5CBfQ3B0l5GzLPZpsuEGe+UzT3kAgGHxA==","shasum":"02c56618787d9f582420967da8a40c3cf24b677c","tarball":"https://registry.npmjs.org/@axis-llc/axis-gupshup-whatsapp/-/axis-gupshup-whatsapp-1.0.2.tgz","fileCount":10,"unpackedSize":33895,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhlMp7CRA9TVsSAnZWagAAh1QP/iTA3rsh+t8zrcTtDqA6\ncO/uFxet8SwZB1WEtZp0oGJUdQgFJbcJBXOnXlvXGHkzmRb80NCOZy0J+NtL\nEuPsdrt7nxjxk3Udq1oxhsxsKPRTklyQE6mFy+ZQ8BGrBXtz6P5n0XNbdgxl\nB8auDfKYQzqdOxqbCdpSh8fHI9+ZOUgo65GjvXpeXM4BV1BxPY+nMy5R9s5d\nEIWr72HCYAZwzJQ7cFBpIQw7JGWBcHSVShTJQ5sYefAjSbkgTEq9AdIxO5zp\nvrQSgynd8IvuUZKuWBq5OuUOXJJVkrU5mpUxXcdWjjcfCKKbna0hdLUQ+mO0\no3tkp9tQBAIqgAg0Ga0PI6wqAPUfGFqlcBolg3LUhK9P4cxFK1/J4miMobfn\nlZj9LE8QO/8XkyzJxTXpGq3xUbilCEDaXRf8FmGGOcuJCeJLE8gg79hZZNbC\nvTARrUdW/At7zmWbo9n9ZYStlIhdUvOtlP8P3bY0ct0KtBCpp+7KrlKbvA8t\n0DIQBtR/9bNX9rOPXL960eFqG7KXIbyj+bixpt8FJ7h3fjjlRLdwUMkc1Fj7\n4851c7lgoCEmABLevJufCxkG55iCKvX1W99yRWZANkemN//4hYwL52bj8Ra/\n2vvc/LKn29wBCet4kPluj3fJmsZ2qVOKEDXjxPLfqW1ruPxfOb6Gachowqff\nAlxx\r\n=xaNp\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIA2Zfg3SI+4wuIlPTy8urg62gTyBIH+wWe8bytCM6GxcAiAOJu5KckTX0G/FgiUKlJcMu/2M9CDLsL5yjnxZfE9eiQ=="}]},"_npmUser":{"name":"belvadev","email":"dev@belvadigital.com"},"directories":{},"maintainers":[{"name":"denga","email":"alex@belvadigital.com"},{"name":"shadracknicholasbelva","email":"shadrack@belvadigital.com"},{"name":"belvadev","email":"dev@belvadigital.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/axis-gupshup-whatsapp_1.0.2_1637141115149_0.001644125716506517"},"_hasShrinkwrap":false}},"time":{"created":"2021-11-17T09:25:14.876Z","1.0.2":"2021-11-17T09:25:15.344Z","modified":"2022-04-04T17:12:20.231Z"},"maintainers":[{"name":"denga","email":"alex@belvadigital.com"},{"name":"shadracknicholasbelva","email":"shadrack@belvadigital.com"},{"name":"belvadev","email":"dev@belvadigital.com"}],"description":"Library to wrap GupShup WhatsApp APIs(v2) for messages and user opt-ins","homepage":"https://github.com/axis-llc/axis-gupshup-whatsapp#readme","keywords":["gupshup","whatsapp-api","messaging-api","messaging","whatsapp"],"repository":{"type":"git","url":"git+https://github.com/axis-llc/axis-gupshup-whatsapp.git"},"author":{"name":"Axis Africa"},"bugs":{"url":"https://github.com/axis-llc/axis-gupshup-whatsapp/issues"},"license":"MIT","readme":"# Gupshup WhatsApp API\n\n## About\n\nA library wrapping Gupshup Whatsapp API (v2) to be able to send Outbound messages of types (text, templates, video, audio, location, contact card, stickers, images) and fetch/send the opt-in requests to the users and the opted-in users list.\n\n> Note: It does not connect with the Inbound APIs (that are responsible for receiving messages from customers through webhooks)\n\n## Installation\n\n```bash\nnpm i axis-gupshup-whatsapp\n```\n\nor\n\n```bash\nyarn add axis-gupshup-whatsapp\n```\n\n## Basic Usage\n\nYou will be needed to create gupshup instance with provided `apiKey`. You can obtain the api key from Whatsapp Dashboard (<https://www.gupshup.io/whatsapp/dashboard>) for your specific app or if you are testing with the sandbox application.\n\n```javascript\nconst Gupshup = require('axis-gupshup-whatsapp')\n\nlet client = new Gupshup({\n    apiKey: 'YOUR_API_KEY',\n})\n```\n\n## Options\n\n### Request Body\n\n| Property      | Type                                | Description                      | Required                          |\n| ------------- | ----------------------------------- | -------------------------------- | --------------------------------- |\n| `channel`     | `string`                            | The channel name, i.e.`whatsapp` | true                              |\n| `destination` | `string`                            | Customer's Whatsapp number       | true                              |\n| `source`      | `string`                            | Your Whatsapp business number    | true                              |\n| `message`     | [Message Payload](#message-payload) | Payload for the sending message  | true                              |\n| `src.name`    | `string`                            | Your whatsapp application name   | false (required for sandbox apps) |\n\n### Message Payload\n\n| Property      | Type                          | Description                                                                                                            | Required |\n| ------------- | ----------------------------- | ---------------------------------------------------------------------------------------------------------------------- | -------- | ----- | ----- |\n| `isHSM`       | `string`                      | `true` (for template message) and `false` (for session message)                                                        | false    |\n| `type`        | `string`                      | Whatsapp message type( `text`, `audio`, `video`, `file`, `image` , `location`, `contact`, `sticker`)                   | true     |\n| `text`        | `string`                      | The text message to be sent to the customer, in case of `type=text`                                                    | false    |\n| `url`         | `string`                      | The public URL where the file / audio / video attachment to be sent to the customer is hosted                          | false    |\n| `originalUrl` | `string`                      | The public URL where the image to be sent to the customer is hosted. Only to be sent for `type = image`                | false    |\n| `previewUrl`  | `string`                      | The public URL where a thumbnail of the image to be sent to the customer is hosted. Only to be sent for `type = image` | false    |\n| `caption`     | `string`                      | Add caption to media messages, applicable to media `type = image                                                       | video    | file` | false |\n| `longitude`   | `number`                      | To be sent for `type = location`                                                                                       | false    |\n| `latitude`    | `number`                      | To be sent for `type = location`                                                                                       | false    |\n| `name`        | `string`                      | Name of the location. Only to be sent for `type = location`                                                            | false    |\n| `address`     | `string`                      | Postal address of the location. Only to be sent for `type = location`                                                  | false    |\n| `contact`     | [Contact Card](#contact-card) | Contact details to be sent when `type = contact`                                                                       | false    |\n\n### Contact Card\n\n| Property    | Type                                          | Description                             | Required |\n| ----------- | --------------------------------------------- | --------------------------------------- | -------- |\n| `addresses` | [[Contact Address](#contact-address)]         | Contact address for the person          | false    |\n| `birthday`  | `string`                                      | Person's date of birth                  | true     |\n| `emails`    | [[Contact Email](#contact-email)]             | Person's email or emails                | true     |\n| `name`      | [Contact Name](#contact-name)                 | Person's first, last and formatted name | true     |\n| `org`       | [Contact Organization](#contact-organization) | Person's organization details           | true     |\n| `phones`    | [[Contact Phone](#contact-phone)]             | Person's contact phone numbers          | true     |\n| `url`       | [[Contact URL](#contact-url)]                 | Person's contact URLs                   | true     |\n\n### Contact Address\n\n| Property      | Type     | Description         | Required |\n| ------------- | -------- | ------------------- | -------- |\n| `city`        | `string` | Eg: \"Menlo Park\"    | true     |\n| `country`     | `string` | Eg: \"United States\" | true     |\n| `countryCode` | `string` | Eg: \"us\"            | true     |\n| `state`       | `string` | Eg: \"CA\"            | true     |\n| `street`      | `string` | Eg: \"1 Hacker Way\"  | true     |\n| `type`        | `string` | Eg: \"HOME\"          | true     |\n| `zip`         | `string` | Eg: \"94025\"         | true     |\n\n### Contact Email\n\n| Property | Type     | Description       | Required |\n| -------- | -------- | ----------------- | -------- |\n| `email`  | `string` | Eg: \"test@fb.com\" | true     |\n| `type`   | `string` | Eg: \"WORK\"        | true     |\n\n### Contact Name\n\n| Property        | Type     | Description      | Required |\n| --------------- | -------- | ---------------- | -------- |\n| `firstName`     | `string` | Eg: \"John\"       | true     |\n| `formattedName` | `string` | Eg: \"John Smith\" | true     |\n| `lastName`      | `string` | Eg: \"Smith\"      | true     |\n\n### Contact Organization\n\n| Property     | Type     | Description    | Required |\n| ------------ | -------- | -------------- | -------- |\n| `company`    | `string` | Eg: \"WhatsApp\" | true     |\n| `department` | `string` | Eg: \"Design\"   | true     |\n| `title`      | `string` | Eg: \"Manager\"  | true     |\n\n### Contact Phone\n\n| Property | Type     | Description             | Required |\n| -------- | -------- | ----------------------- | -------- |\n| `phone`  | `string` | Eg: \"+1 (650) 555-1234\" | true     |\n| `type`   | `string` | Eg: \"WORK\"              | true     |\n| `wa_id`  | `string` | Eg: \"16505551234\"       | false    |\n\n### Contact URL\n\n| Property | Type     | Description                    | Required |\n| -------- | -------- | ------------------------------ | -------- |\n| `url`    | `string` | Eg: \"https://www.facebook.com\" | true     |\n| `type`   | `string` | Eg: \"WORK\"                     | true     |\n\n## Supported Resources\n\n-   [Messages](#messages)\n-   [User Opt-ins](#user-opt-ins)\n\n### Messages\n\n**1. Send Text Message**\n\n```javascript\nclient.message\n    .send({\n        channel: 'whatsapp',\n        source: '917834811114',\n        destination: '919876543210',\n        'src.name': 'GupshupAppTest',\n        message: {\n            isHSM: 'false',\n            type: 'text',\n            text: 'hi there',\n        },\n    })\n    .then((response) => {\n        console.log('Text message sent', response)\n    })\n    .catch((err) => {\n        console.log('Text message err:', err)\n    })\n```\n\n**2. Send Template Message**\n\n```javascript\nclient.message\n    .send({\n        channel: 'whatsapp',\n        source: '917834811114',\n        destination: '919876543210',\n        'src.name': 'GupshupAppTest',\n        message: {\n            isHSM: 'true',\n            type: 'text',\n            text: 'Hi Ashwamegh, your order is confirmed and will be delivered to you by 15 Feb',\n        },\n    })\n    .then((response) => {\n        console.log('Template text message sent', response)\n    })\n    .catch((err) => {\n        console.log('Template text message err:', err)\n    })\n```\n\n**3. Send Image as a Message**\n\n-   Supported Content-Types: image/jpeg, image/png\n-   maximum file size: 5 MB\n\n```javascript\nclient.message\n    .send({\n        channel: 'whatsapp',\n        source: '917834811114',\n        destination: '919876543210',\n        'src.name': 'GupshupAppTest',\n        message: {\n            type: 'image',\n            originalUrl:\n                'https://www.buildquickbots.com/whatsapp/media/sample/jpg/sample01.jpg',\n            previewUrl:\n                'https://www.buildquickbots.com/whatsapp/media/sample/jpg/sample01.jpg',\n            caption: 'Sample image',\n        },\n    })\n    .then((response) => {\n        console.log('Image message sent', response)\n    })\n    .catch((err) => {\n        console.log('Image message err:', err)\n    })\n```\n\n**4. Send Document/File as a Message**\n\n-   Supported Content-Types: Any valid MIME-type\n-   maximum file size: 100 MB\n\n```javascript\nclient.message\n    .send({\n        channel: 'whatsapp',\n        source: '917834811114',\n        destination: '919876543210',\n        'src.name': 'GupshupAppTest',\n        message: {\n            type: 'file',\n            url: 'https://www.buildquickbots.com/whatsapp/media/sample/pdf/sample01.pdf',\n            filename: 'Sample file',\n        },\n    })\n    .then((response) => {\n        console.log('Document message sent', response)\n    })\n    .catch((err) => {\n        console.log('Document message err:', err)\n    })\n```\n\n**5. Send Audio as a Message**\n\n-   Supported Content-Types: audio/aac, audio/mp4, audio/amr, audio/mpeg, audio/ogg; codecs=opus. Note: The base audio/ogg type is not supported.\n-   maximum file size: 16 MB\n\n```javascript\nclient.message\n    .send({\n        channel: 'whatsapp',\n        source: '917834811114',\n        destination: '919876543210',\n        'src.name': 'GupshupAppTest',\n        message: {\n            type: 'audio',\n            url: 'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3',\n        },\n    })\n    .then((response) => {\n        console.log('Audio message sent', response)\n    })\n    .catch((err) => {\n        console.log('Audio message err:', err)\n    })\n```\n\n**6. Send Video as a Message**\n\n-   Supported Content-Types: video/mp4, video/3gpp. Note: Only H.264 video codec and AAC audio codec is supported.\n-   maximum file size: 16 MB\n\n```javascript\nclient.message\n    .send({\n        channel: 'whatsapp',\n        source: '917834811114',\n        destination: '919876543210',\n        'src.name': 'GupshupAppTest',\n        message: {\n            type: 'video',\n            url: 'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4',\n            caption: 'Sample video',\n        },\n    })\n    .then((response) => {\n        console.log('Video message sent', response)\n    })\n    .catch((err) => {\n        console.log('Video message err:', err)\n    })\n```\n\n**6. Send Location as a Message**\n\n```javascript\nclient.message\n    .send({\n        channel: 'whatsapp',\n        source: '917834811114',\n        destination: '919876543210',\n        'src.name': 'GupshupAppTest',\n        message: {\n            type: 'location',\n            longitude: 43.43,\n            latitude: 33.34,\n            name: 'Name of the location',\n            address: 'Postal address',\n        },\n    })\n    .then((response) => {\n        console.log('Location message sent', response)\n    })\n    .catch((err) => {\n        console.log('Location message err:', err)\n    })\n```\n\n**7. Send Contact Card as a Message**\n\n```javascript\nclient.message\n    .send({\n        channel: 'whatsapp',\n        source: '917834811114',\n        destination: '919876543210',\n        'src.name': 'GupshupAppTest',\n        message: {\n            type: 'contact',\n            contact: {\n                addresses: [\n                    {\n                        city: 'Menlo Park',\n                        country: 'United States',\n                        countryCode: 'us',\n                        state: 'CA',\n                        street: '1 Hacker Way',\n                        type: 'HOME',\n                        zip: '94025',\n                    },\n                    {\n                        city: 'Menlo Park',\n                        country: 'United States',\n                        countryCode: 'us',\n                        state: 'CA',\n                        street: '200 Jefferson Dr',\n                        type: 'WORK',\n                        zip: '94025',\n                    },\n                ],\n                birthday: '2012-08-18',\n                emails: [\n                    {\n                        email: 'test@fb.com',\n                        type: 'WORK',\n                    },\n                    {\n                        email: 'test@whatsapp.com',\n                        type: 'WORK',\n                    },\n                ],\n                name: {\n                    firstName: 'John',\n                    formattedName: 'John Smith',\n                    lastName: 'Smith',\n                },\n                org: {\n                    company: 'WhatsApp',\n                    department: 'Design',\n                    title: 'Manager',\n                },\n                phones: [\n                    {\n                        phone: '+1 (940) 555-1234',\n                        type: 'HOME',\n                    },\n                    {\n                        phone: '+1 (650) 555-1234',\n                        type: 'WORK',\n                        wa_id: '16505551234',\n                    },\n                ],\n                urls: [\n                    {\n                        url: 'https://www.facebook.com',\n                        type: 'WORK',\n                    },\n                ],\n            },\n        },\n    })\n    .then((response) => {\n        console.log('Contact Card sent', response)\n    })\n    .catch((err) => {\n        console.log('Contact Card err:', err)\n    })\n```\n\n**8. Send Sticker as a Message**\n\n```javascript\nclient.message\n    .send({\n        channel: 'whatsapp',\n        source: '917834811114',\n        destination: '919876543210',\n        'src.name': 'GupshupAppTest',\n        message: {\n            type: 'sticker',\n            url: 'https://cdn.getstickerpack.com/storage/uploads/sticker-pack/tunes-traffic/7.png',\n        },\n    })\n    .then((response) => {\n        console.log('Location message sent', response)\n    })\n    .catch((err) => {\n        console.log('Location message err:', err)\n    })\n```\n\n#### Messages API Response\n\n```json\n{ \"status\": \"submitted\", \"messageId\": \"ee4a68a0-1203-4c85-8dc3-49d0b3226a35\" }\n```\n\n### User Opt-ins\n\n**1. Get Opt-in users list**\n\n```javascript\nclient.optins\n    .getUsers('GupshupAppTest')\n    .then((response) => {\n        console.log('Optins User list: ', response)\n    })\n    .catch((err) => {\n        console.log('Optins User list error: ', err)\n    })\n```\n\n#### API Response\n\n```json\n{\n    \"status\": \"success\",\n    \"users\": [\n        {\n            \"countryCode\": \"91\",\n            \"lastMessageTimeStamp\": 1585593959851,\n            \"optinSource\": \"URL\",\n            \"optinStatus\": \"OPT_IN\",\n            \"optinTimeStamp\": 1585504095053,\n            \"phoneCode\": \"8x98xx21x4\"\n        }\n    ]\n}\n```\n\n**2. Send User Opt-in Request**\n\n```javascript\nclient.optins\n    .sendUserOptinRequest({\n        appName: 'GupshupAppTest',\n        userMobileNumber: 919876543210,\n    })\n    .then((response) => {\n        console.log('Optin request sent: ', response)\n    })\n    .catch((err) => {\n        console.log('Optin request error: ', err)\n    })\n```\n\n#### API Response\n\n```json\n{\n    \"status\": 202\n}\n```\n\n## Development\n\n```bash\nyarn install\n```\n\n## Testing\n\n```bash\nyarn test\n```\n","readmeFilename":"README.md"}