|
| 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) |
0 commit comments