# web3-mq-snaps

> mq-web3 snap provides more possibilities for building web3 social dapps

Latest version **1.0.8** (published 2023-01-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install web3-mq-snaps
pnpm add web3-mq-snaps
yarn add web3-mq-snaps
bun add web3-mq-snaps
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2023-01-06 |
| First published | 2022-09-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16.0.0 |
| Dependencies | 4 |
| Unpacked size | 174.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | fanxiangyu |
| Keywords | chat, messaging, conversation |

## Links

- npm: https://www.npmjs.com/package/web3-mq-snaps
- Repository: https://github.com/Generative-Labs/new-web3-mq-snap
- Homepage: https://github.com/Generative-Labs/new-web3-mq-snap#readme
- Issues: https://github.com/Generative-Labs/new-web3-mq-snap/issues
- npm.io page: https://npm.io/package/web3-mq-snaps

## Dependencies (4)

- [js-sha3](https://npm.io/package/js-sha3.md) ^0.8.0
- [query-string](https://npm.io/package/query-string.md) ^7.1.1
- [@noble/ed25519](https://npm.io/package/@noble/ed25519.md) ^1.6.1
- [@protobuf-ts/plugin](https://npm.io/package/@protobuf-ts/plugin.md) ^2.7.0

## Recent versions

- 1.0.8 (latest) — 2023-01-06
- 1.0.6 — 2022-12-12
- 1.0.5 — 2022-09-23
- 1.0.4 — 2022-09-20
- 1.0.3 — 2022-09-20
- 1.0.2 — 2022-09-16
- 1.0.1 — 2022-09-16
- 1.0.0 — 2022-09-16
- 0.0.2 — 2022-09-16

## README

# Web3-mq snap

mq-web3 snap provides more possibilities for building web3 social dapps

You can familiarize yourself with mq-web3 snap based on the following example

Before starting, you need to install the [flask plugin](https://chrome.google.com/webstore/detail/metamask-flask-developmen/ljfoeinjpaedjfecbmggjgodbgkmjkjk?hl=zh-CN) on your browser. After the plugin is installed, execute the following code in your dapp to install the mq-web3 snap

## Installation

```javascript
const connect = async function () {
  await window.ethereum.request({
    method: "wallet_enable",
    params: [
      {
        wallet_snap: {
          ["npm:web3-mq-snaps"]: {
            version: "^1.0.6",
          },
        },
      },
    ],
  });
};
connect();
```

## Methods

| name              | type     | Parameters Description                                                                                     | response                                                                                                  |
| ----------------- | -------- |------------------------------------------------------------------------------------------------------------| --------------------------------------------------------------------------------------------------------- |
| creatRoom         | function | 1.group_name?: string 2. avatar_url ?: string                                                              | Object: Web3-MQ Client                                                                                    |
| queryChannelList  | function | 1. options: [PageParams](https://docs.web3mq.com/docs/Web3MQ-SDK/JS-SDK/types/#pageparams)                 | Promise: [activechanneltype](https://docs.web3mq.com/docs/Web3MQ-SDK/JS-SDK/types/#activechanneltype)[]   |
| getTargetUserId   | function | 1. address: string                                                                                         | Promise: [searchusersresponse](https://docs.web3mq.com/docs/Web3MQ-SDK/JS-SDK/types/#searchusersresponse) |
| sendMessage       | function | 1. msg: string 2. topic : string                                                                           | Promise: void                                                                                             |
| getMessageList    | function | 1. options: [PageParams](https://docs.web3mq.com/docs/Web3MQ-SDK/JS-SDK/types/#pageparams) 2.topic: string | Promise: [messagelistitem](https://docs.web3mq.com/docs/Web3MQ-SDK/JS-SDK/types/#messagelistitem)[]       |
| sendNotifyMessage | function | 1. message: string                                                                                         | Promise: void                                                                                             |


# Useage
### creatRoom()
> Create Web3MQ chat room
```ts
const createRoomsBySnaps = async (roomName: string = "") => {
  return await ethereum.request({
    method: "wallet_invokeSnap",
    params: [
      newSnapId,
      {
        method: "creatRoom",
        payload: { group_name: roomName },
      },
    ],
  });
};
```
### queryChannelList()
> Get user all channel list
```ts
const getChannelListBySnaps = async () => {
  //@ts-ignore
  return await ethereum.request({
    method: "wallet_invokeSnap",
    params: [
      newSnapId,
      {
        method: "queryChannelList",
        payload: { options: { page: 1, size: 100 } },
      },
    ],
  });
};
```
### getTargetUserId()
> Get Web3MQ userid by wallet address
```ts
const getUserIdByAddress = async (address: string) => {
    //@ts-ignore
    return await ethereum.request({
        method: "wallet_invokeSnap",
        params: [
            newSnapId,
            {
                method: "getTargetUserId",
                payload: address,
            },
        ],
    });
}
```
### sendMessage()
> Send Message to chat room or Web3MQ user 
```ts
const sendMessageBySnaps = async (msg: string, topic: string) => {
  //@ts-ignore
  return await ethereum.request({
    method: "wallet_invokeSnap",
    params: [
      newSnapId,
      {
        method: "sendMessage",
        payload: { msg, topic },
      },
    ],
  });
};

```
### getMessageList()
> Get channel history message
```ts
const getMessagesBySnaps = async (topic: string) => {
    //@ts-ignore
    return await ethereum.request({
        method: "wallet_invokeSnap",
        params: [
            newSnapId,
            {
                method: "getMessageList",
                payload: {
                    options: { page: 1, size: 100 },
                    topic,
                },
            },
        ],
    });
}

```
### sendNotifyMessage()
```ts

export const sendNotifyMessage = async (message: string) => {
    //@ts-ignore
    return await ethereum.request({
        method: "wallet_invokeSnap",
        params: [
            newSnapId,
            {
                method: "sendNotifyMessage",
                payload: { message },
            },
        ],
    });
};
```

---
_Source: https://npm.io/package/web3-mq-snaps · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
