{"id":27429384,"url":"https://github.com/byteball/obyte-browser-chat","last_synced_at":"2025-04-14T14:17:30.165Z","repository":{"id":46022704,"uuid":"422239397","full_name":"byteball/obyte-browser-chat","owner":"byteball","description":"A library for chats between browser and wallet","archived":false,"fork":false,"pushed_at":"2021-11-19T15:10:18.000Z","size":329,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T14:17:29.420Z","etag":null,"topics":["chatbot","dapp","obyte"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/byteball.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-28T14:36:45.000Z","updated_at":"2021-11-19T15:10:20.000Z","dependencies_parsed_at":"2022-09-14T11:22:45.878Z","dependency_job_id":null,"html_url":"https://github.com/byteball/obyte-browser-chat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byteball%2Fobyte-browser-chat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byteball%2Fobyte-browser-chat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byteball%2Fobyte-browser-chat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byteball%2Fobyte-browser-chat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/byteball","download_url":"https://codeload.github.com/byteball/obyte-browser-chat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248894940,"owners_count":21179153,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatbot","dapp","obyte"],"created_at":"2025-04-14T14:17:28.518Z","updated_at":"2025-04-14T14:17:30.137Z","avatar_url":"https://github.com/byteball.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Obyte browser chat\n\nA library for establishing chat sessions between your web-based dapp and the user's [Obyte](https://obyte.org) wallet. Use the chat to:\n\n* request payments, including payments in multiple assets;\n* request to sign a message;\n* request user's address (without having to copy/paste);\n* request private profiles (such as real name attestations);\n* request a vote in a poll.\n\n*This library uses local storage*\n\n## Install\n``yarn add obyte-browser-chat obyte``\n\n## Use\n```js\nimport browserChat from \"obyte-browser-chat\"\n```\n \n## Example\n\n### 1. Create an instance of obyte.js client\n```js \nimport obyte from \"obyte\";\n\nexport default new obyte.Client('wss://obyte.org/bb-test'); // or wss://obyte.org/bb for livenet\n```\n\n### 2. Create an instance of chat\n```js \nimport browserChat from \"obyte-browser-chat\";\n\nimport client from \"...\"; // obyte.js client instance\n\nexport default browserChat({\n  name: \"mydomain.com\", // chat name that'll show up in the user's wallet\n  client, // obyte.js client instance\n  testnet: true\n});\n```\n\n\n### 3. Use\n```js \nimport browserChatInstance from \"...\"; \n\nconst payments = [\n  {\n    address: \"2QVJOY3BRRGWP7IOYL64O5BU3WLUJ4TZ\",\n    amount: 1e9, // integer, amount in smallest units\n    asset: \"base\"\n  },\n  {\n    address: \"EJC4A7WQGHEZEKW6RLO7F26SAR4LAQBU\",\n    amount: 2e9,\n    asset: \"base\"\n  }\n];\n\nconst paymentJsonBase64 = browserChatInstance.generatePaymentString({ payments });\n\nconst message = `Send bytes \\n[send](payment:${paymentJsonBase64})`;\n\nconst link = browserChatInstance.sendMessageAfterPairing(message);\n\n...\n\n\u003ca href={link}\u003eClick\u003c/a\u003e\n```\n\n## Methods\n\n### getPairingLink - Returns a link for pairing\n\n```js\nconst pairingLink = browserChatInstance.getPairingLink();\n```\nReturns a link that looks like `obyte:PUB_KEY@obyte.org/bb`. The user needs to click it to open the chat.\n\n### sendMessageAfterPairing - Returns a link for pairing\n\n```js\nconst pairingLink = browserChatInstance.sendMessageAfterPairing(\"We're glad to see you\");\n```\nAs above, plus the provided message will be sent to the user immediately after pairing.\n\n### onPairing - Callback function triggered after pairing\n```js\nbrowserChatInstance.onPairing((msgObject) =\u003e {\n  console.log(\"msgObject\", msgObject);\n\n  // send a plain text message\n  msgObject.reply(\"Hi there!\");\n\n  // request to sign a text message\n  msgObject.reply(\"Please prove ownership of your address by signing this message: [any text](sign-message-request:I confirm for domain.com that I own the address SPV5WIBQQT4DMW7UU5GWCMLYDVNGKECD)\");\n\n  // request to sign an object\n  const order = {field1: \"value1\"};\n  const orderJsonBase64 = Buffer.from(JSON.stringify(order), 'utf8').toString('base64');\n  msgObject.reply(`Please sign an order: [any text](sign-message-request:${orderJsonBase64})`);\n\n  // request a private profile\n  msgObject.reply(`Click this link to reveal your private profile to us: [any text](profile-request:first_name,last_name,dob,country,id_type).`);\n\n  // request a vote\n  const objVote = {\n    poll_unit: '0Vv6lhpjjk3VsKCSGML2NY/5W+WgpsNELQJ1rukhL5Y=',\n    choice: 'Institute For the Future of the University of Nicosia',\n  };\n  const voteJsonBase64 = Buffer.from(JSON.stringify(objVote), 'utf8').toString('base64');\n  msgObject.reply(`Click to vote for ${objVote.choice}: [any text](vote:${voteJsonBase64}).`);\n\n});\n```\nwhere `msgObject` contains:\n* `reply` - message forwarding function \n* `body` - object with `pairing_secret` field\n* `sender` - sender's public key\n\n### onMessage - Callback function triggered when a message is received\n\n```js\nbrowserChatInstance.onMessage((msgObject) =\u003e {\n  msgObject.reply(\"Thanks, you said: \" + msgObject.body);\n});\n```\nwhere `msgObject` contains:\n* `reply` - message forwarding function \n* `body` - received message (string)\n* `sender` - sender's public key\n\n### onReady - Callback function triggered when the device gets connected to the hub\n\n```js\nbrowserChatInstance.onReady(() =\u003e {\n  console.log(\"I'm connected to the hub\");\n});\n```\n\n### generatePaymentString - Function that converts the payment object to base64\n\n```js\nconst payments = [\n  {\n    address: \"2QVJOY3BRRGWP7IOYL64O5BU3WLUJ4TZ\",\n    amount: 1e9,\n    asset: \"base\"\n  },\n  {\n    address: \"EJC4A7WQGHEZEKW6RLO7F26SAR4LAQBU\",\n    amount: 2e9,\n    asset: \"base\"\n  }\n];\n\nconst paymentJsonBase64 = chatInstance.generatePaymentString({ payments });\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyteball%2Fobyte-browser-chat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbyteball%2Fobyte-browser-chat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyteball%2Fobyte-browser-chat/lists"}