-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevnotes.txt
213 lines (146 loc) · 6.3 KB
/
devnotes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#################################################
# #
# Notes #
# #
#################################################
# "server_hellonode.js"
# https://nodejs.org/en/download/package-manager/
# "index_express.js"
# didn't work out
#as per the following guide: https://www.sohamkamani.com/blog/2016/09/21/making-a-telegram-bot/
# https://aqueous-plains-66613.herokuapp.com/
# Ctrl+Shift+B - run a task (here: 'npm start')
#################################################
# #
# VS Code #
# #
#################################################
# Ctrl+Shift+P >Task
#################################################
# #
# Node.js #
# #
#################################################
#run server:
node server.js
#run server (debug):
node --inspect server,js
# install npm package <package> locally
npm install <package>
# globally
sudo npm install -g <package>
#################################################
# #
# Telegram Bot API #
# #
#################################################
#=====# Webhooks #=====#
#webhooks info:
# https://core.telegram.org/bots/api#getting-updates
#check current webhook
curl https://api.telegram.org/bot<TOKEN>/getWebhookInfo
#set webhook to ZEIT now (runs in local)
curl -F "url=https://kukinterviewer-dev.now.sh/new-message" https://api.telegram.org/bot<TOKEN>/setWebhook
#which is equivalent to
curl https://api.telegram.org/bot<TOKEN>/setWebhook?url=https://kukinterviewer-dev.now.sh/new-message
#set webhook to heroku
curl -F "url=https://aqueous-plains-66613.herokuapp.com/new-message" https://api.telegram.org/bot<TOKEN>/setWebhook
#which is equivalent to
curl https://api.telegram.org/bot<TOKEN>/setWebhook?url=https://aqueous-plains-66613.herokuapp.com/new-message
#################################################
# #
# Node Telegram Bot API (module) #
# #
#################################################
# https://github.com/yagop/node-telegram-bot-api
#################################################
# #
# NOW #
# #
#################################################
#=====# Run (runs on the local machine) #=====#
now login
now
now --prod
node index.js
#################################################
# #
# Heroku #
# #
#################################################
# https://devcenter.heroku.com/articles/heroku-cli
Heroku requires an app to listen to the port specified by Heroku in an env var PORT.
Otherwise it shuts the app down within a minute.
app domain: https://aqueous-plains-66613.herokuapp.com/
#=====# Create #=====#
git add -A && git commit -m 'Telegram API test run'
heroku create
git remote -v
heroku git:remote -a aqueous-plains-66613
git push heroku master
#=====# Run (local) #=====#
heroku login #when running first time, or logged out
heroku local web
#=====# Run (server) #=====#
git add -A && git commit -m "<commit_name>"
heroku login #when running first time, or logged out
git push heroku master
heroku open
#turn service off:
heroku ps:scale web=0
#turn service on:
heroku ps:scale web=1
#OR:
bash pushheroku.sh "<commit_message>"
#to change the message of last commit:
bash pushheroku.sh --amend
#to restart heroku web service
bash pushheroku.sh restart
#=====# Log (server) #=====#
# https://devcenter.heroku.com/articles/logging
# << Logs originate from many sources (router nodes, dynos, etc.) and are assembled into a single log stream by Logplex.
# So logs might be collected and delivered out of order >>
# all logs, tail
heroku logs --tail
# all logs, tail 200 lines
heroku logs -n 200
# dynos router
heroku logs --dyno router
# source app
heroku logs --source app
# source app, then dyno worker
heroku logs --source app --dyno worker
#################################################
# #
# Dev log #
# #
#################################################
#this source
#https://medium.com/make-school/how-to-deploy-your-node-js-mongodb-app-to-the-web-using-heroku-63d4bccf2675
#suggests:
heroku addons:create mongolab:sandbox
#the following found addon suggests it is free for up to 496 MB:
#https://elements.heroku.com/addons/mongolab
#from the command above it said check
#https://devcenter.heroku.com/categories/billing and
#https://heroku.com/verify
#I checked, added credit card, and ran the command again, so that it installed the addon
#dashboard https://dashboard.heroku.com/apps/aqueous-plains-66613 says addon added and its still $0.00/month plan
#proceeding on the medium article above:
npm install mongoose
npm install dotenv
#<< push your .env variables to Heroku (if you have any): >>
heroku config:set DATABASE_URI=database_uri_here
# --- 2020.04.30
# finished CRUD
# - add internal incremental id field 'qid' to the Question schema
# - test deleting recieved and sent message
# - rewrite bot.onText to one single function that reacts on any text, then switch case with regex.
# - there has to be a global exported condition checking if bot's reaction function is already running, so that bot won't react on second pending message
# -
# - add userfrieldly commands
# - add deleting queue for bot
# --- Mongoose DB structure notes:
# Schemas are like tables in a RDBMS, also are recipes for Models.
# Models are like run-time validation objects compiled from corresponding Schemas for table entries, but model is instead of a table.
# Documents like are those entries, except they are not rows, but rather instance objects of corresponding Model class.