beckn / beckn/sandbox

Using Redis Pub/Sub for callbacks streaming via sandbox.

Open
#14 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
0
Forks
7
PR merge metrics
No merged PRs in 30d

Description

I see that right now the default points to docker webhooks in sandbox [here](https://github.com/beckn/DEG/blob/p2p-trading/testnet/p2p-trading-interdiscom-devkit/install/docker-compose-adapter-p2p.yml)

Proposing modifications to sandbox such that we can enable interoperable communication, abstracting a lot of the logic for builders.

### In order to recieve the callback at the same place as of action,

```
import { P2PEnergy } from '../p2p-energy';

const initObject = {
persona: process.env.PERSONA, // enum BAP, BPP, BOTH
bapServerUrl: process.env.BAPSERVER_URL || "",
bppServerUrl: process.env.BPPSERVER_URL || "",
redisUrl: process.env.REDIS_URL || "",
channelId: process.env.channelId || "", // ensure same channel name across devices if you are listening.
usecase: "p2p-trading" // enum of different usecases, right now static
}

const client = new P2PEnergy.init(initObject);

await client.connect();
const response = p2p.action(payload).then((onActionResponse) => console.log(onActionResponse));
or
// response resolves only when onAction comes back via redis channel otherwise returns a promise.
const response = await p2p.action(payload);
await client.disconnect();
```

### In Order to receive callback at BPP's device or BAP's device or to multiple agents in between.

```
// in order to receive the callback on other device (initObject must be same)
await p2p.action(payload);

// in other device
client.on('action', (onActionResponse) => {
console.log("Received action callback:", onActionResponse);
});
```

### In Order to have a custom middleware for db / agentic logic / or even verification logic.
```
// rest of it remains same as above.

const middleware = async (ctx, next) => {
if (['search', 'confirm'].includes(ctx.action)) {
console.log(`[VC] Verifying ${ctx.payload.vc_id}`);
// await vcService.verify(ctx.payload.vc_id);
}
return next();
};

const response = await client.action(payload, middleware);

old way,
client.action(payload, middleware).then((response) => {
console.log(response);
});
```

I was able to listen to :3001, :3002 and log callbacks as shown in the image below, I can make this work end to end to create pull request for other devs as well.

Image

Looking forward for comments on the proposed architechture for sandbox using redis as pub sub.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with testnet/p2p-trading-interdiscom-devkit/install/docker-compose-adapter-p2p.yml and trace the P2PEnergy.init, connect, action, and disconnect entry points described in the issue. Review how callbacks currently reach :3001 and :3002 before assessing Redis Pub/Sub and middleware integration. Done should demonstrate the proposed callback flows end to end, including the middleware example, with agreed acceptance criteria and tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, redis, typescript
Domain
backend, devops, distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.