danneu / telegram-chatgpt-bot

a Telegram ChatGPT bot that supports text prompts and two-way voice memos
33 stars 8 forks source link

Finish adding default voices #13

Open danneu opened 1 year ago

danneu commented 1 year ago

Languages like Arabic ("ar") still have no default voice. :(

lucaslearnscode commented 1 year ago

Hello Dan, I ran "npm index.js" during installation, but there is actually no "index.js" file, only an "index.ts" file. How can I resolve this? I'm a beginner, sorry

danneu commented 1 year ago

Sorry. Yeah, the readme is incorrect and out of date since the project is written in Typescript, not Javascript.

node index.js for Typescript is ts-node index.ts

So install ts-node: npm install --global ts-node

Now ts-node index.ts should start the project.

You can also compile the project to a single javascript file:

npm install --global @vercel/ncc
ncc -s build index.ts -o dist
node dist/index.js

I'll have to update the readme.

If you look in package.json, you'll see the scripts I personally use: https://github.com/danneu/telegram-chatgpt-bot/blob/d5e60097e4f464f5c3138b1153481836ea57c3df/package.json#L3-L6

lucaslearnscode commented 1 year ago

Thank you very much for your answer. I love this project and it helps me practice my English. I also wanted to know if this project can run on a single Ubuntu VPS, including the bot itself and the PostgreSQL database. Because when I tried to run index.ts, there was an error indicating that the DATABASE_URL was problematic.

danneu commented 1 year ago

Yes, this project takes up very few resources since it only does I/O. I have it running on the cheapest AWS EC2 instance.

If you have an "always online" computer in your house like a desktop computer, you can run this project there and use a Cloudflare Tunnel to point a domain like chat.example.com to the app running on your home computer. That's actually what I do during development. That's what I'm doing with the cloudflared tunnel run chatdev command in package.json which points https://chatdev.danneu.com to my localhost app when I'm working on the code so that I can receive Telegram webhook events on my laptop.

Also, yes, you have to get postgres running somewhere (on the same machine is fine). Create a database called "telegram_chat" or something. And then execute the contents of "schema.sql" on that database to create the tables.

Sorry it's not easier to set up.

lucaslearnscode commented 1 year ago

I have completed all the settings and after running "npm start", it shows "listening on localhost:8080". Does this mean the program has run successfully? I have also seen the Commands in the Telegram bot, but there is no response when I send messages to the bot. I use ubuntu 20.04, node version 20.0, npm version 9.6.5.

FYI, when I enable IPv6 on the VPS, "npm start" will report errors. However, when I disable IPv6, "npm start" runs successfully.

danneu commented 1 year ago

If the bot initializes and begins listening on localhost, that means it was able to send and receive requests to Telegram's API and it is now listening for webhook events on localhost:8080/telegram.

Now you need to route the WEBHOOK_URL that you configured in .env to localhost:8080. (Edit: I just remembered that Telegram requires the webhook url to be https:, not http:)

I'm not the best at explaining this on the spot, you should be able to find resources online since you have to solve the common problem of how to route a domain name to localhost:<port> on your VPS. Except it's made more complicated because the connection needs to use https (Telegram's API requires this).

If you have a domain name, you can download and run the Caddy server on your VPS to route https://foo.example.com to localhost:8080 and it will do HTTPS termination.

caddy reverse-proxy --from foo.example.com --to localhost:8080

I personally point my danneu.com domain name to use Cloudflare.com as my DNS which gives me https: for free. Then I've told Cloudflare to route https://chat.danneu.com to my VPS IP address. On my VPS, I use the Apache webserver to reverse-proxy requests to chat.danneu.com to localhost:8080.

But Caddy is probably the simpler option since it has a one-line solution to do all this (you just need a domain name). Most importantly, it gives you HTTPS support.

Hopefully this isn't too daunting. Just know that this is what everyone has to go through to host a web application on a server and expose it to the internet, so it's a trusty skill.

lucaslearnscode commented 1 year ago

I finally successfully deployed this robot application, and I think the problem was with my webhook. I also put my domain on Cloudflare. Thank you very much for your patient response!

danneu commented 1 year ago

Cool. Tell me if you have any problems. :)