Skip to content

Commit 7c7a7c6

Browse files
64ixLe-Caignec
andauthored
feat: Web3Messaging integration guide (#46)
Co-authored-by: Robin Le Caignec <[email protected]> Co-authored-by: Le-Caignec <[email protected]>
1 parent d68429a commit 7c7a7c6

File tree

4 files changed

+135
-118
lines changed

4 files changed

+135
-118
lines changed

.vitepress/sidebar.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ export function getSidebar() {
253253
text: 'Run iApp without ProtectedData',
254254
link: '/guides/use-iapp/run-iapp-without-ProtectedData',
255255
},
256+
{
257+
text: 'Integrate Web3 Messaging',
258+
link: '/guides/use-iapp/web3-messaging',
259+
},
256260
],
257261
},
258262
],
@@ -566,10 +570,7 @@ export function getSidebar() {
566570
},
567571
],
568572
},
569-
{
570-
text: 'Integration Guide',
571-
link: '/references/web3telegram/integration-guide',
572-
},
573+
573574
{
574575
text: 'Advanced Configuration',
575576
link: '/references/web3telegram/advanced-configuration',

src/guides/use-iapp/web3-messaging.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
title: Integrate Web3 Messaging (Web3Mail & Web3Telegram)
3+
description:
4+
End-to-end guide to send messages with Web3Mail (email) and Web3Telegram
5+
(Telegram) using iExec — protect identifiers, grant access, and send securely
6+
---
7+
8+
# Integrate Web3 Messaging
9+
10+
This guide covers both Web3Mail (email) and Web3Telegram (Telegram) toolkit. The
11+
flow is the same, except that:
12+
13+
- For Web3Mail, you only need the user's email address.
14+
- For Web3Telegram, you only need the user's Telegram Chat ID.
15+
16+
## Overview
17+
18+
1. (Telegram only) Get a Chat ID from the iExec bot
19+
2. Create the Protected Data using DataProtector Toolkit
20+
3. Grant access of your Protected Data
21+
4. Send the message using the relevant SDK ( Web3Mail / Web3Telegram )
22+
23+
## 1. Retrieve the Telegram Chat ID (Telegram only)
24+
25+
Ask the recipient to open Telegram and start a conversation with
26+
[@IExecWeb3TelegramBot](https://t.me/IExecWeb3TelegramBot). The bot replies with
27+
a unique Chat ID.
28+
29+
::: tip
30+
31+
- Once the Chat ID is protected, all messages will arrive within this bot
32+
conversation.
33+
- The recipient can leave the conversation at any time to stop receiving
34+
messages.
35+
36+
:::
37+
38+
## 2. Create the Protected Data
39+
40+
Protect the email address or Chat ID using DataProtector Core.
41+
42+
::: code-group
43+
44+
```ts twoslash [Web3Mail]
45+
import { IExecDataProtectorCore, getWeb3Provider } from '@iexec/dataprotector';
46+
const web3Provider = getWeb3Provider('PRIVATE_KEY');
47+
const dataProtectorCore = new IExecDataProtectorCore(web3Provider);
48+
49+
const protectedData = await dataProtectorCore.protectData({
50+
data: {
51+
52+
},
53+
});
54+
```
55+
56+
```ts twoslash [Web3Telegram]
57+
import { IExecDataProtectorCore, getWeb3Provider } from '@iexec/dataprotector';
58+
const web3Provider = getWeb3Provider('PRIVATE_KEY');
59+
const dataProtectorCore = new IExecDataProtectorCore(web3Provider);
60+
61+
const protectedData = await dataProtectorCore.protectData({
62+
data: {
63+
telegram_chatId: '12345678',
64+
},
65+
});
66+
```
67+
68+
:::
69+
70+
## 3. Grant Access
71+
72+
Grant permission for a sender and/or an app to contact the user.
73+
74+
```ts twoslash
75+
import { IExecDataProtectorCore, getWeb3Provider } from '@iexec/dataprotector';
76+
const web3Provider = getWeb3Provider('PRIVATE_KEY');
77+
const dataProtectorCore = new IExecDataProtectorCore(web3Provider);
78+
79+
const grantedAccess = await dataProtectorCore.grantAccess({
80+
protectedData: '0x123abc...',
81+
authorizedApp: '0x456def...',
82+
authorizedUser: '0x789cba...',
83+
pricePerAccess: 3,
84+
numberOfAccess: 10,
85+
});
86+
```
87+
88+
## 4. Send the Message
89+
90+
::: code-group
91+
92+
```ts twoslash [Web3Mail]
93+
import { IExecWeb3mail, getWeb3Provider } from '@iexec/web3mail';
94+
95+
const web3Provider = getWeb3Provider('PRIVATE_KEY');
96+
const web3mail = new IExecWeb3mail(web3Provider);
97+
98+
const sendEmail = await web3mail.sendEmail({
99+
protectedData: '0x123abc...',
100+
emailSubject: 'My email subject',
101+
emailContent: 'My email content',
102+
// useVoucher: true,
103+
});
104+
```
105+
106+
```ts twoslash [Web3Telegram]
107+
import { IExecWeb3telegram, getWeb3Provider } from '@iexec/web3telegram';
108+
109+
const web3Provider = getWeb3Provider('PRIVATE_KEY');
110+
const web3telegram = new IExecWeb3telegram(web3Provider);
111+
112+
const sendTelegram = await web3telegram.sendTelegram({
113+
protectedData: '0x123abc...',
114+
senderName: 'Arthur',
115+
telegramContent: 'My telegram message content',
116+
});
117+
```
118+
119+
:::
120+
121+
## Payment
122+
123+
Each message sent through Web3Mail or Web3Telegram requires payment in RLC
124+
tokens.
125+
126+
For detailed information about payment methods, pricing, and voucher usage, see
127+
our comprehensive guide:
128+
[How to pay for executions](/guides/use-iapp/how-to-pay-executions)

src/references/web3telegram.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ telegram chat ID recipients through use of Ethereum addresses.
1919
iExec's protocol the telegram chat ID as a `protectedData` entity using
2020
[iExec Data Protector](/references/dataProtector). Through this mechanism, users
2121
have complete control over which applications may use their
22-
[chat ID](/references/web3telegram/integration-guide#_1-get-your-users-to-retrieve-their-chat-id)
23-
for sending communications.
22+
[chat ID](/guides/use-iapp/web3-messaging#retrieve-chat-id) for sending
23+
communications.
2424

2525
Sending a user a message, therefore, requires knowledge of the Ethereum address
2626
of their `protectedData` as well as an explicit authorization for your account

src/references/web3telegram/integration-guide.md

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)