{"_id":"@bcm-one/messaging-sdk","_rev":"6-91d91c782fbf442efdbb6a3b0ab2a7bd","time":{"1.0.0":"2021-07-07T18:53:02.175Z","created":"2021-07-09T15:32:39.116Z","1.0.1":"2021-07-09T15:32:39.616Z","modified":"2022-04-04T18:02:03.940Z","1.0.2":"2021-07-12T14:15:46.032Z","1.0.3":"2021-07-16T15:30:07.407Z"},"name":"@bcm-one/messaging-sdk","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.1":{"name":"@bcm-one/messaging-sdk","version":"1.0.1","description":"Wrapper to easily manage connections with Messaging platform","main":"dist/index.js","scripts":{"build":"tsc","dev":"$NODE_ENV='dev' & ./node_modules/.bin/tsc -w","format-check":"prettier -l src","format":"prettier --write src","test":"jest tests/"},"license":"MIT","devDependencies":{"@types/jest":"^26.0.20","prettier":"^2.2.1","ts-jest":"^26.4.4","ts-node":"^9.1.1","typescript":"^4.1.3","jest":"^26.6.3"},"dependencies":{"axios":"^0.21.1","dotenv":"^8.2.0"},"gitHead":"63fc112b7ecbcdcbcbba618529f24eb1e49931cc","_id":"@bcm-one/messaging-sdk@1.0.1","_nodeVersion":"15.11.0","_npmVersion":"7.6.0","dist":{"integrity":"sha512-22hwvi82K0Qw4Cc4TIPH+KQb3B+vlU3Z+W+bJ9uxoNIPbwpKczem9LwI8IdMCpg/4cReoETjzJb1/auQylDzaQ==","shasum":"50f072e9b45b79f3cd8f433891cb6d292d2a205c","tarball":"https://registry.npmjs.org/@bcm-one/messaging-sdk/-/messaging-sdk-1.0.1.tgz","fileCount":40,"unpackedSize":32975,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg6GwXCRA9TVsSAnZWagAAqnEP/juQXzBHkzYButEE+Zsl\nNIU7zgLxOWUAgBf7nsrxBqeZklgBRFgRNtom8Z7gga7nnVzfn4hTVZ7cwHLq\nVDlRpG0hkP9DcunFlMnhhlQqsBCErdfpy5/GcmEPxdLrgFW72sASUa9SZb9O\nT5fK8RzPAxSnIXDbQuC8aKpVJ0e/WLvA4ph+rzNNPlt3l/aPhMj5xTL9x0LT\nJ0tH3t5LMeGHHY+4PXrGYWou6Ppf+YjcbEnAb3eXBhcSRzBWu0gvlWEEaHAY\nnXnT842I48eyL0V+cXmi9F8/0tHBmdnkL/p02haW0dUy6SpJyvsJ4dGVzzlh\nGzh7yNB/6iConO2vU8u8oMZ7ZPmwnxTpCHb5JIlhwRzzkHLaTHaszFnaJJp7\nN3b3TTWVcGW6pDMnjHu+TE9RXpI0N9DZnvO21aem5StJ63EY6J3AjQwB/Vnj\nCD2Ek0Fr9CuzZ/kdCyVfWWna87A2pEuGvvXqBV/k4ukL2r8Dtn0kRG0KTq3p\nkiX9eUU1frkB4geYk+VNgNar7eQCHaPpbTcbC9MVEbq3GL9TaEjcLLjqF1Iq\n7FcC9XjK9EvrlFDIpaW2mTZ++kULBmiu1ZQFVk+gZFSn8RNzrPKV6jN0HUDc\n+v0d/Lm6vcfh5y4NLlBUApl3B7DaCTYt+x8wRdMkt/91kFMOTg8HF4/EO1lm\nNGVQ\r\n=5GTr\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD+H8b22z2wTzJvff77ey9iGrwe0dGVHiqCP3bqcMHiiwIhAKWN3iXXlliOjmhBylOMAsnE/RO31H7FNY7MLyvvIV6P"}]},"_npmUser":{"name":"darren.eberly","email":"darren@sip.us"},"directories":{},"maintainers":[{"name":"darren.eberly","email":"darren@sip.us"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/messaging-sdk_1.0.1_1625844759481_0.5333396329549063"},"_hasShrinkwrap":false},"1.0.2":{"name":"@bcm-one/messaging-sdk","version":"1.0.2","description":"Wrapper to easily manage connections with Messaging platform","main":"dist/index.js","scripts":{"build":"tsc","dev":"$NODE_ENV='dev' & ./node_modules/.bin/tsc -w","format-check":"prettier -l src","format":"prettier --write src","test":"jest tests/"},"license":"MIT","devDependencies":{"@types/jest":"^26.0.20","jest":"^26.6.3","prettier":"^2.2.1","ts-jest":"^26.4.4","ts-node":"^9.1.1","typescript":"^4.1.3"},"dependencies":{"axios":"^0.21.1","dotenv":"^8.2.0"},"gitHead":"797852fd46904d69dbc43c4eeb8fad1e642555ef","_id":"@bcm-one/messaging-sdk@1.0.2","_nodeVersion":"15.11.0","_npmVersion":"7.6.0","dist":{"integrity":"sha512-VMKuY3hRZKZ0Tqmp9ZPXCCaT5CLXS052rmAxVtnPeFFsmCzkevgbXOpM/RAFsJ/35xPazo1AvsYdWjPchMMSAw==","shasum":"0d64b526e121173031a7cd0d44a16841d6cee12f","tarball":"https://registry.npmjs.org/@bcm-one/messaging-sdk/-/messaging-sdk-1.0.2.tgz","fileCount":41,"unpackedSize":37741,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg7E6SCRA9TVsSAnZWagAAZokP/3cHzBgQXOTSXB1YGO6p\nIiycavZD0yoKwDcLx4fK0YbzCCRerlunPMogVpg2alNumwdtgg21Yqad5vaN\n1Y723wAQDlF91bzM4Gc3GKWHZRd2OBaYKehfGKUOtoScY+uNgATgYrHR9I1r\n8D8pBu1Sb8UWhA91Com52LsOz1k5hsJ/RZLK/AdnKYSqppqHsah6Pm+qczvc\nlwPQymqNORpzg7oeJZFT//9H0RiQXV1n3sa522inNhELGgVQCxB45Fwj/2++\nCLz/0ltoJcq6mtVhGT1sLK5K28ar22uwvjkeX5gca1ELFd9eWFJTWZ4qXRfs\n+BlKwQldEVoPfxWLy8saQqg706WX295OjDYzoFXCVkeiq2kcJLXACgGxFlrR\np51h/e/ASocNllZ9jYtrMGO5QWgo0EvUcRLQ0IN7RdTBTNgPTLW76VLLLUAj\n7PKIVEctNty83xNw2cMICaNrbGn/HC1uN24LAWnl/JZDW5LEAWTOnIly3ZvF\nLKJsyU29cGRgEQk/I0MpUXPjIfLVMyGfFLw/+4o25eKapKUU8ADI/Yp7qCWI\nBhDOqogg55ldrjcCM5WaJEBOno417yH4kLnLmPbxlcXsOWXqgTC/l/qTJ1Xe\nQjSBrbiKRKrQPdY0DlrPj3z+yHWu7h9wRzdvan6PlDWpVRy/pLoLX5tKdarb\nEVgd\r\n=10Uc\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQChwyccZHL6KdnBULKJzyI8u3+W5vAtfu+qwUec6GRVjAIgMvhAQuybbUzBJYNw1jRuI5DsWOgtPi8uySVu0xBJQ4M="}]},"_npmUser":{"name":"darren.eberly","email":"darren@sip.us"},"directories":{},"maintainers":[{"name":"darren.eberly","email":"darren@sip.us"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/messaging-sdk_1.0.2_1626099345875_0.07586196048841631"},"_hasShrinkwrap":false},"1.0.3":{"name":"@bcm-one/messaging-sdk","version":"1.0.3","description":"Wrapper to easily manage connections with Messaging platform","main":"dist/index.js","scripts":{"build":"tsc","dev":"$NODE_ENV='dev' & ./node_modules/.bin/tsc -w","format-check":"prettier -l src","format":"prettier --write src","test":"jest tests/"},"license":"MIT","devDependencies":{"@types/jest":"^26.0.20","jest":"^26.6.3","prettier":"^2.2.1","ts-jest":"^26.4.4","ts-node":"^9.1.1","typescript":"^4.1.3"},"dependencies":{"axios":"^0.21.1","dotenv":"^8.2.0"},"gitHead":"4b53fdc7490dfd5d8474e650198ece748d83055e","_id":"@bcm-one/messaging-sdk@1.0.3","_nodeVersion":"16.4.0","_npmVersion":"7.18.1","dist":{"integrity":"sha512-PBaDnSJhGjjUklvmDW+1dKpmFB+bCIuaxMoWcDic+cpeglxm6bYxxSr0NKcShtRAKwjdBA4sDdqESwwu1vC/dw==","shasum":"c2f5dc9a63b626fca0c4852dde5024d7f82982e3","tarball":"https://registry.npmjs.org/@bcm-one/messaging-sdk/-/messaging-sdk-1.0.3.tgz","fileCount":40,"unpackedSize":38625,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg8aX/CRA9TVsSAnZWagAA6zIP/jA+NL71dmd3rK/BLQGF\nvRCQjelGtSd2Lr57D3c5skHAFNXKYioS6VCujBJqGSr7zTgYyUk6iB4nTBZW\nDRfe2GbuJTmhw/Lgqf3o7gfTvRRqTTqJuHGkPLeZKYSvA8L/84BiXA/eHBW+\n7NPCMMMXKJGlvG7VHCwYaQZsfXq33cmX0ch+ek3zkRgWQKXn8SogJf3JSCeQ\nmDaMEPaoFNAkCVlSAl8M7ZFVNVQy6C3vnRby08qRWeaNTQ+2wUbnuup5mREp\nmc2iAtpufpYrB8S+IhjLDqUEshxyjoIhlSMnakLV1+FDYYKnMZ7zhctf9qlU\nF/IlYKMIftj3mR2UXMP9+N/hYCNmro0ZoIwPv/QQ2UDwxHz0P8rKtR77K+gl\n8qaV7xJJqJC6Zy8YZRI1nr6m5V0OqexJxIypyDUgL+rml4aBokCpIBthqAF0\nsWaKzd2P4oYskpwDPNxR8PjNj49YTvNlrBCrvGNX8Jwe4wp83UeyCHO4FGJA\n+VGOz3wEbLraTwOjvDEnto0m4hsWP/nuz142rStSBpqxLDnvJ82FtnhZDc3h\nOy0PkM3OgKR2P+tnY7kRg19JJpkSwhPqJHPG6k8mD2IgWeDRJ2/vSBmay1Hy\n/RlrOuQEzeIgBr6Sx92/zMPyDsqtV3IIVq5jdfiHO3qk2uFQxSXJTVT11tjO\nE3f9\r\n=DE6y\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDKUMTEu25u1xVss8lZPGMIEdTy6j4+iUzjAijNxriEVwIhALkL7FSmaL6g/JxsNSW286TLfOYga7s3F+nFH1Gko+gv"}]},"_npmUser":{"name":"darren.eberly","email":"darren@sip.us"},"directories":{},"maintainers":[{"name":"darren.eberly","email":"darren@sip.us"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/messaging-sdk_1.0.3_1626449407266_0.20389420606742803"},"_hasShrinkwrap":false}},"maintainers":[{"name":"darren.eberly","email":"darren@sip.us"}],"description":"Wrapper to easily manage connections with Messaging platform","license":"MIT","readme":"# BCM One Messaging SDK\n\n<!-- omit in toc -->\n- Messaging SDK\n- [Installation and initialization](#installation-and-initialization)\n- [Sending messages](#sending-messages)\n  - [Sending SMS](#send-sms)\n    - [SMS Responses](#sms-responses)\n    - [Successful Responses](#successful-responses)\n    - [Error Responses](#error-responses)\n- [Using TypeScript](#using-typescript)\n\n\n## Installation and initialization\n\n- In an empty folder initialize npm\n\n```bash\nnpm init\n```\n\n- Install the npm Messaging package\n```bash\nnpm i @bcm-one/messaging-sdk\n```\n\n- Create a js file\n```bash\ntouch main.js\n```\n\n**Now edit your main.js file:**\n\n- Import `messaging` from `@bcm-one/messaging-sdk`\n\n```javascript\nimport { messaging } from '@bcm-one/messaging-sdk';\n```\n\n`messaging` is an utility function that accepts a `username` and a password as arguments and return an instance of the `Messaging` class.\n\n- Initialize the `Messaging` instance\n\n```javascript\n\nconst myUsername = 'username';\nconst myPassword = 'password';\n\nconst msg = messaging(username, password)\n```\n\n### Congratulations! Now you can send messages!<br><br><br>\n\n## Sending Messages\n\nCurrently, `messaging` package, allows to send SMS.\nOther functionality are currently in development.\n\n## Send SMS\n\nOnce the messaging instance is initialized you can simply send SMS in the form of a JavaScript object:\n\n```javascript\nconst sms = {\n    from: '12345678909',\n    to: '12345678908',\n    message: 'Hello world!'\n}\n```\n\n- `from`: a string representing a valid and registered DID. This DID must be associated with the `username` and `password` provided during the initialization of the messaging instance.\n\n- `to`: a string representing the DID number of recipient.\n\n- `message`: a string representing the content of the message.\n\nin order to send the SMS, just call `sendSMS` method on the messaging instance, passing the sms payload as argument.\n\n```javascript\nmsg.sendSMS(sms)\n```\n\n## SMS Responses\n\n`sendSMS` method can return a `MessageResponse` or an `ErrorResponse` in the form of a Promise. To resolve the promise you can use the modern JS syntax with `async` and `await`, enclosing `sendSMS` in an asynchronous function.\n\n```javascript\n// In this case, sendSMS is enclosed in a self calling async anonymous function \n;(async () => {\n  try {\n    const response = await msg.sendSMS(sms)\n    console.log(response)\n  } catch (error) {\n    console.log(error)\n  }\n})()\n```\n\nOr you can use `then` and `catch` syntax\n\n```javascript\nmsg\n  .sendSMS(sms)\n  .then(response => {\n    console.log(response)\n  })\n  .catch(err => {\n    console.log(err)\n  })\n```\n\n## Successful responses\n\nSuccessful responses have a `statusCode` of `202` on the resolved response object.\nThey also report the sender (`from`), the recipient (`to`), the message sent (`message`) along with a unique identifier.\n\nThis is an example of a successful MessageResponse:\n\n```javascript\n{\n  from: '14707343234',\n  to: '19171212121',\n  message: 'Hello world',\n  id: '473ebf4f-0997-430c-92ca-051725bc9c60',\n  statusCode: 202\n}\n```\n\n## Error responses\n\nAn error response has a `statusCode` that is different from `202`. Note that all the HTTP errors are returned as a simple response without the need to `try and catch` them because `messaging` handles them behind the hood.\n\nAn Error response provides more information about how the error generated on the `detail` key of the ErrorResponse object.\n\nThis is an example of an error response:\n\n```javascript\n{\n  detail: 'Resource not found\\n' +\n    '\\n' +\n    '        You are trying to send a message from a not registered DID\\n' +\n    'Error: from',\n  statusCode: 404\n}\n```\n\nSince HTTP errors are returned on the same response you can differentiate them comparing the status code.\n\n```javascript\n;(async () => {\n    const response = await msg.sendSMS(sms)\n    if (response.statusCode === 202){\n        console.log(response)\n    } else {\n      console.log('In this case an error occurred')\n      console.log('On response.detail you can find more details about the error')\n      console.log(response.detail)\n    }\n})()\n```\n\nThis provides a much more cleaner way to handle your HTTP response rather than using `try and catch`.\n\n## Using TypeScript\nMessaging provides type definitions for developers that want to use TypeScript.\n\nJust make sure to create a custom type guard to define the response datatype.\nHere an example\n\n```typescript\nimport { messaging, SMS, SMSResponse } from '@bcm-one/messaging-sdk';\n\nconst myPass = \"password\"\nconst myuser = \"username\"\n\nconst msg = messaging(myuser, myPass)\n\nconst sms: SMS = {\n    from: \"12345678901\",\n    to: \"12343212345\",\n    message: \"Hello world!\"\n}\n\n\nconst isSuccessfulResponse = (response: any): response is SMSResponse =>{\n    return response.statusCode === 202;\n}\n\nmsg.sendSMS(sms).then(response => {\n    if(isSuccessfulResponse(response)){\n        console.log(\"Got a successful response!\")\n        console.log(\"MESSAGE: \", response.message)\n        console.log(\"FROM: \", response.from)\n        console.log(\"TO: \", response.to)\n        console.log(\"ID: \", response.id)\n    } else {\n        console.log(\"Type guard exclude SMS response\")\n        console.log(\"Error status code: \", response.statusCode)\n        console.log(\"Error detail: \", response.detail)\n    }\n})\n```\nIn this example, `isSuccessfulResponse` act as a type guard. If the status code is 202 that mean that the response is `SMSResponse`, while if not is an `ErrorResponse`.","readmeFilename":"README.md"}