Spanish guide version here
The following document is intended to provide the necessary information to prepare the work environment for the development of the bot by providing the technical and physical characteristics of each element.
Allow people to trade with other people on Telegram using the Lightning Network. The lnp2pbot is developed in Node.js and connects to an LND (Lightning Network Daemon) node is a full implementation of a Lightning Network node.
Achieving that the telegram bot is able to receive payments Lightning without being custodian. Users won't need permission to use the service or provide personal data that could compromise their privacy, thus maintaining full custody of their assets at all times. The bot will use hold invoices and will only settle the seller's invoices when both parties agree. Immediately after this, the bot will pay the buyer's invoice.
Reach all users who want to acquire non-custodial Bitcoin satoshis through a Telegram bot.
- Computer with internet access.
- Node management system Polar or LND node.
-
Docker: automation of application deployment as portable, self-sufficient containers that can run in the cloud or locally.
-
MogoDB: database manager system.
$ node -v
In case it's not installed:
- On Mac run the following command:
$ brew install node
- On Linux and Windows, go to the following link.
Create a directory where you will place the mongo.yml
file for MongoDB:
$ mkdir mongodb
$ cd mongodb
$ nano mongo.yml
The contents of the mongo.yml
file must be:
version: "3.7"
services:
mongodb:
image: mongo:5.0
environment:
MONGO_INITDB_ROOT_USERNAME: mongoadmin
MONGO_INITDB_ROOT_PASSWORD: secret
volumes:
- ./mongodb-data/:/data/db
ports:
- 27017:27017
To start MongoDB, run the following command:
$ docker compose -f mongo.yml up
Clone the bot repository and navigate to the project directory:
$ git clone https://github.com/lnp2pBot/bot.git
$ cd bot
$ npm install
In the root directory of the project, you will find a sample .env-sample
file. Copy that file and edit it to configure your environment variables:
$ cp .env-sample .env
$ nano .env
To connect to an LND
node, you need to set several variables in the .env
file created in the previous step:
-
LND_CERT_BASE64: TLS certificate of the LND node in base64 format. You can obtain it with the command:
~/.lnd/tls.cert | tr -d '\n'
. -
LND_MACAROON_BASE64: Macaroon file in base64 format. This file contains permissions to perform actions on the LND node. You can obtain it with the command:
~/.lnd/data/chain/bitcoin /mainnet/admin.macaroon | tr -d '\n',
-
LND_GRPC_HOST: IP address or domain name of the LND node and the port, separated by a colon. Example:
192.168.0.2:10009
.
If you are using Polar, you can obtain the necessary information as shown in the following image:
Here are the variables you need to modify in the .env
file. The remaining variables can either keep their default values or be adjusted as you see fit:
LND_CERT_BASE64=''
LND_MACAROON_BASE64=''
LND_GRPC_HOST=''
BOT_TOKEN=''
DB_USER='mongoadmin'
DB_PASS='secret'
DB_HOST='127.0.0.1'
DB_PORT='27017'
DB_NAME='lnp2pbot'
MONGO_URI='mongodb://mongoadmin:secret@localhost/lnp2pbot?authSource=admin'
CHANNEL='@your-offers-channel'
ADMIN_CHANNEL='-10*****46'
HELP_GROUP='@your-support-group'
FIAT_RATE_EP='https://api.yadio.io/rate'
DISPUTE_CHANNEL='@your-dispute-channel'
NOSTR_SK=''
RELAYS=''
Details of some variables:
-
BOT_TOKEN: You will need to go to Telegram and open @BotFather. Run the menu and choose
Create a new bot
where you will select the bot's name and username. Once generated, it will show you a token that you will place in this field. -
CHANNEL: This is the channel where the bot posts offers. Create a channel on Telegram by pressing the button to write a new message. On Android, it is in the bottom right corner with a round icon featuring a pencil, and on iOS, it is in the top right corner with a small pencil-shaped icon. Press the
New Channel
option. Then, set the bot as a channel's administrator (open the bot and select: Add to a group or channel). Channel has to be public. Part aftert.me/
in link shown in channel info is what goes into CHANNEL property (e.g. if link ist.me/foo
then value should be@foo
). -
ADMIN_CHANNEL: This channel is where the bot sends relevant information to administrators, such as payments failures, when a user takes an order but doesn't proceed, among other things. In this field, you need to enter the channel ID. To obtain it, write a message in the channel, forward it to the
@JsonDumpBot
, and it will show you a JSON with the channel ID. More information can be found here. You need to add the bot as a channel's administrator.
-
HELP_GROUP: This is the group where you will provide bot support. You can create a new group or use an existing one.
-
DISPUTE_CHANNEL: This channel is where the bot posts disputes for solvers to take on (it's not a channel for resolving disputes, just for claiming them). You need to create this channel on Telegram and add the bot as an administrator.
-
NOSTR_SK: The private key for Nostr that will publish the bot's offers as a replaceable parameterized event type 38383. If you do not want your bot to publish offers on Nostr, comment out this variable.
-
RELAYS: The Nostr relays that the Nostr user of your bot will connect to in order to publish offers. If you do not want your bot to publish offers on Nostr, comment out this variable.
$ npm start
- For testing purposes:
$ npm test
After completing the Installation steps:
Start the bot with the command:
/start
It will display a menu, we will choose the /sell
option to sell with the necessary requirements.
- In the channel you will see the offer, you must choose to buy with the other Telegram user.
- Take the order in the channel. Click on Buy Satoshis.
- Enter the bot and click continue.
This is the message that will be displayed.
- Create invoice in Polar with some of the users and paste in Telegram. Choose
Create Invoice
in the behavior part.
- Set the sales quantity.
- Choose
Copy and Close.
- Enter the
bot
and paste the invoice.
A request for payment will be sent to the seller and will be displayed in the bot.
.
- Paste the invoice in Polar and pay it.
- When someone takes the order, the
bot
will display the following message:
- The following will be displayed in the
bot
for the other user:
- The user must release the funds with the command
/fiatsent
, to do this he must copy and paste with theid
- The
bot
will indicate that the user has already sent the fiat money.
- The user must release the funds with the
/release
command by copying and pasting with theid
.
- Finally, the buyer will be notified that the transaction has been successfully completed.