|
| 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). The flow is |
| 11 | +the same, except that: |
| 12 | + |
| 13 | +- For Web3Mail, you only need the user's email address. |
| 14 | +- For Web3Telegram, you must first retrieve the user's Telegram Chat ID. |
| 15 | + |
| 16 | +## Overview |
| 17 | + |
| 18 | +1. (Telegram only) Retrieve the Chat ID from the iExec bot |
| 19 | +2. Create the `protectedData` using DataProtector |
| 20 | +3. Grant access with DataProtector |
| 21 | +4. Send the message using the relevant SDK |
| 22 | + |
| 23 | +## 1. Retrieve the Telegram Chat ID (Telegram only) {#retrieve-chat-id} |
| 24 | + |
| 25 | +Ask the recipient to open Telegram and start a conversation with |
| 26 | +[@IExecWeb3TelegramBot](https://t.me/IExecWeb3TelegramBot). The bot replies with |
| 27 | +their 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 | +## 2. Create the Protected Data |
| 37 | + |
| 38 | +Protect the identifier using DataProtector Core. |
| 39 | + |
| 40 | +### Web3Mail — protect the email address |
| 41 | + |
| 42 | +```ts twoslash |
| 43 | +import { IExecDataProtectorCore, getWeb3Provider } from '@iexec/dataprotector'; |
| 44 | +const web3Provider = getWeb3Provider('PRIVATE_KEY'); |
| 45 | +const dataProtectorCore = new IExecDataProtectorCore(web3Provider); |
| 46 | + |
| 47 | +const protectedData = await dataProtectorCore.protectData({ |
| 48 | + data: { |
| 49 | + |
| 50 | + }, |
| 51 | +}); |
| 52 | +``` |
| 53 | + |
| 54 | +### Web3Telegram — protect the Chat ID |
| 55 | + |
| 56 | +```ts twoslash |
| 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 | +## 3. Grant Access |
| 69 | + |
| 70 | +Grant permission for a sender and/or an app to contact the user. |
| 71 | + |
| 72 | +```ts twoslash |
| 73 | +import { IExecDataProtectorCore, getWeb3Provider } from '@iexec/dataprotector'; |
| 74 | +const web3Provider = getWeb3Provider('PRIVATE_KEY'); |
| 75 | +const dataProtectorCore = new IExecDataProtectorCore(web3Provider); |
| 76 | + |
| 77 | +const grantedAccess = await dataProtectorCore.grantAccess({ |
| 78 | + protectedData: '0x123abc...', |
| 79 | + authorizedApp: '0x456def...', |
| 80 | + authorizedUser: '0x789cba...', |
| 81 | + pricePerAccess: 3, |
| 82 | + numberOfAccess: 10, |
| 83 | +}); |
| 84 | +``` |
| 85 | + |
| 86 | +## 4. Send the Message |
| 87 | + |
| 88 | +### Web3Mail — sendEmail |
| 89 | + |
| 90 | +```ts twoslash |
| 91 | +import { IExecWeb3mail, getWeb3Provider } from '@iexec/web3mail'; |
| 92 | + |
| 93 | +const web3Provider = getWeb3Provider('PRIVATE_KEY'); |
| 94 | +const web3mail = new IExecWeb3mail(web3Provider); |
| 95 | + |
| 96 | +const sendEmail = await web3mail.sendEmail({ |
| 97 | + protectedData: '0x123abc...', |
| 98 | + emailSubject: 'My email subject', |
| 99 | + emailContent: 'My email content', |
| 100 | + // useVoucher: true, |
| 101 | +}); |
| 102 | +``` |
| 103 | + |
| 104 | +### Web3Telegram — sendTelegram |
| 105 | + |
| 106 | +```ts twoslash |
| 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 | + // useVoucher: true, |
| 117 | +}); |
| 118 | +``` |
| 119 | + |
| 120 | +## Payment |
| 121 | + |
| 122 | +See the full payment guide: |
| 123 | +[/guides/use-iapp/how-to-pay-executions](/guides/use-iapp/how-to-pay-executions) |
0 commit comments