typpo / textbelt

Free API for outgoing SMS
https://textbelt.com/
MIT License
3.01k stars 508 forks source link

Your guide to easily deploy a standalone version is here :) #176

Open ryanckulp opened 1 year ago

ryanckulp commented 1 year ago

update - i've just forked a deployable version to reduce some of the steps below.

hi folks,

i noticed a bunch of you (#140, #172, #135, #120, #119, #88) are struggling to get this working on your own server. below is a free and easy solution!

first, i suggest you get it running locally via the included README instructions:

# 1. install dependencies
npm install # for reference, i used node 16.17.0

# 2. config your email inside lib/config.js (using Gmail as an example)
- host: 'smtp.gmail.com'
- auth: {  user:  'youraddress@gmail.com' }
- auth: { pass: make app-specific Gmail password: https://security.google.com/settings/security/apppasswords

# 3. run the server 
redis-server # should default to port 6379
node server/app.js # in a new terminal tab! keep redis running separately

# 4. try sending a text message
curl -X POST http://localhost:9090/text \
   -d number=<your-cell-phone> \
   -d "message=I sent this message for free with Textbelt"

when this works, you're ready to deploy. push this code up to a new PRIVATE GitHub repository (since we added SMTP credentials), or change those hard-coded values to environment variables.

git add .
git commit -m 'prepare textbelt for deploy'
git remote set-url origin https://github.com/yourusername/your_new_repo

deploying a self-hosted version of Textbelt

  1. create a free account at https://render.com. this is basically like Heroku. i've never used it until today, not a promo.
  2. click to make a "Web Service" from your dashboard or click New > Web Service from navigation
  3. auth your GitHub and select the textbelt repository you created
  4. name your app, e.g. textbelt, then set Environment to Node, Build Command to npm install, and Start Command to node server/app.js
  5. select the free Instance Type
  6. if you refactored lib/config.js to use environment variables, plug those in by clicking Advanced > Add Environment Variable
  7. click Create Web Service at the very bottom

this will build and deploy your code. when it's done, click the URL generated by Render and you should see the "homepage" saying I'm online!.

now for the final task. if you try creating a text message via our previous strategy:

curl -X POST https://your-textbelt-server.onrender.com/text \
  -d number=<your-cell-phone> \
  -d "message=A free text message with Textbelt on Render"

you'll likely get a CANNOT Post response with some HTML markup. i couldn't figure out why Render blocks the request as the server already has CORS enabled.

to fix this, simply modify your code inside server/app.js:

// before
app.post('/text', (req, res) => {

// after
app.get('/text', (req, res) => {

Render won't complain about cross origin GET requests. inside your Render project dashboard click "Manual Deploy" to update your server with the /text endpoint HTTP method update.

you'll be up and running in seconds! enjoy.

globemediaofficial commented 1 year ago

Awesome! I love that this solution doesn't have to be hosted on a host computer since it uses render.com.

aryangupta24 commented 1 year ago

I am getting a error - Invalid phone number

curl -X POST http://textbelt-05ea.onrender.com/text \ -d number='+14052955384' \ -d "message=I sent this message for free with Textbelt"

brian404 commented 8 months ago

what name shuld i use for envioment varibale lib/config.js

ryanckulp commented 8 months ago

what name shuld i use for envioment varibale lib/config.js

i'm not sure what you are referring to. here is the lib/config.js source. which variable, which line of code?

https://github.com/founderhacker/textbelt_deployable/blob/master/lib/config.js

brian404 commented 8 months ago

i've deployed it on my vps the endpoint is working but after i try sending a message i get this {"success":false,"message":"Invalid phone number."}⏎ ┌[parrot]─[20:28-12/01]─[/home/brian/Downloads] └╼brian$

On Fri, 12 Jan 2024 at 20:21, Ryan Kulp @.***> wrote:

what name shuld i use for envioment varibale lib/config.js

i'm not sure what you are referring to. here is the lib/config.js source. which variable, which line of code?

https://github.com/founderhacker/textbelt_deployable/blob/master/lib/config.js

— Reply to this email directly, view it on GitHub https://github.com/typpo/textbelt/issues/176#issuecomment-1889681578, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARMKYQCM2GECGPD3L6IGBNLYOFWKZAVCNFSM6AAAAAATNKJD2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBZGY4DCNJXHA . You are receiving this because you commented.Message ID: @.***>

ryanckulp commented 8 months ago

i suggest trying another number first. perhaps the one you tested is already blacklisted.

brian404 commented 8 months ago

I am getting a error - Invalid phone number

curl -X POST http://textbelt-05ea.onrender.com/text -d number='+14052955384' -d "message=I sent this message for free with Textbelt"

same error man

brian404 commented 8 months ago

can you give it a try and give feedback please └╼brian$curl http://165.22.121.181:9090/text I'm online!⏎ http://165.22.121.181:9090/text

On Fri, 12 Jan 2024 at 20:32, Ryan Kulp @.***> wrote:

i suggest trying another number first. perhaps the one you tested is already blackli

Reply to this email directly, view it on GitHub https://github.com/typpo/textbelt/issues/176#issuecomment-1889695539, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARMKYQCO5MRS77BSKLZE2YTYOFXRFAVCNFSM6AAAAAATNKJD2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBZGY4TKNJTHE . You are receiving this because you commented.Message ID: @.***>