Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lopezjurip/chat-intent

Parse phone number to create intents for chat apps
https://github.com/lopezjurip/chat-intent

Last synced: 25 days ago
JSON representation

Parse phone number to create intents for chat apps

Awesome Lists containing this project

README

        

# chat-intent

[![dependencies][dependencies-image]][dependencies-url] [![dev-dependencies][dev-dependencies-image]][dev-dependencies-url] [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

## Getting started

Install the main `chat-intent` and the middleware you may need as `chat-intent-whatsapp` and `chat-intent-telegram`:

```sh
yarn add chat-intent chat-intent-whatsapp chat-intent-telegram
```

Create URIs, URLs and parsed phone number:

```js
const ChatIntent = require("chat-intent").default;
const intentWhatsapp = require("chat-intent-whatsapp").default;
const intentTelegram = require("chat-intent-telegram").default;

const intent = new ChatIntent();
intent.use(ChatIntent.middleware.validate());
intent.use(ChatIntent.middleware.encodeText());
intent.use(intentWhatsapp());
intent.use(intentTelegram());

const { result } = intent.generate("+56 9 8765 4321", { text: "Hello World!" });
console.log(result);
```

Output

```json
{
"identifier": "56987654321",
"phone": "+56 9 8765 4321",
"country": "CL",
"code": "56",
"valid": true,
"whatsapp": {
"browser": "https://web.whatsapp.com/send?phone=56987654321&text=Hello+World!",
"native": "whatsapp://send?phone=56987654321&text=Hello+World!"
},
"telegram": {
"native": "tg://msg?to=+56987654321&text=Hello+World!"
}
}
```

## Development

Clone and install dependencies:

```sh
git clone https://github.com/mrpatiwi/chat-intent.git
cd chat-intent
yarn
```

[dependencies-image]: https://david-dm.org/mrpatiwi/chat-intent.svg
[dependencies-url]: https://david-dm.org/mrpatiwi/chat-intent
[dev-dependencies-image]: https://david-dm.org/mrpatiwi/chat-intent/dev-status.svg
[dev-dependencies-url]: https://david-dm.org/mrpatiwi/chat-intent#info=devDependencies