From 9fd4225efd17052b44f251e2059588b3256b806c Mon Sep 17 00:00:00 2001 From: ahmed fadhil Date: Thu, 25 Jan 2018 11:29:26 +0100 Subject: [PATCH 1/7] adds pg --- Gemfile | 3 ++- Gemfile.lock | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 83f6a54..e304487 100644 --- a/Gemfile +++ b/Gemfile @@ -123,7 +123,7 @@ group :development, :test do gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] gem 'selenium-webdriver' # Use sqlite3 as the database for Active Record - gem 'sqlite3' + #gem 'sqlite3' gem 'railroady' end @@ -149,6 +149,7 @@ group :development do # For call-stack profiling flamegraphs (requires Ruby MRI 2.0.0+) gem 'flamegraph' gem 'stackprof' # For Ruby MRI 2.1+ + gem 'pg', '0.20.0' end group :production do diff --git a/Gemfile.lock b/Gemfile.lock index 35dab84..2a0de37 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -293,7 +293,6 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sqlite3 (1.3.13) sshkit (1.15.0) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) @@ -391,7 +390,6 @@ DEPENDENCIES sinatra spring spring-watcher-listen (~> 2.0.0) - sqlite3 stackprof telegram-bot-ruby therubyracer From d583552f5d5a8f443cedd7d6afff031132d3f33e Mon Sep 17 00:00:00 2001 From: ahmed fadhil Date: Thu, 25 Jan 2018 16:51:54 +0100 Subject: [PATCH 2/7] debugging and modification --- Gemfile | 8 +-- Gemfile.lock | 4 +- README.md | 13 ++++- app/controllers/webhooks_controller.rb | 1 + config/environments/development.rb | 2 +- config/secrets.yml | 5 +- lib/bot_v2/dispatcher.rb | 76 +++++++++++++------------- lib/bot_v2/feedback_manager.rb | 2 +- telegram_webhook_req | 4 +- 9 files changed, 65 insertions(+), 50 deletions(-) diff --git a/Gemfile b/Gemfile index 83f6a54..d1017dd 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,8 @@ end gem 'aasm', '~> 4.12', '>= 4.12.3' gem 'record_tag_helper', '~> 1.0' - +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 5.1.4' # writing and deploying cron jobs. # gem 'whenever', :require => false @@ -64,11 +65,10 @@ gem 'awesome_print' # Authentication solution gem 'devise' -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 5.1.1' + # Use Puma as the app server -gem 'puma', '~> 3.7' +gem 'puma', '~> 3.10.0' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' diff --git a/Gemfile.lock b/Gemfile.lock index 35dab84..0e37f89 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -375,10 +375,10 @@ DEPENDENCIES pg (= 0.20.0) polling prawn (~> 2.2, >= 2.2.2) - puma (~> 3.7) + puma (~> 3.10.0) rack-mini-profiler railroady - rails (~> 5.1.1) + rails (~> 5.1.4) rails-assets-eq.js rails-assets-jquery rails-assets-mdl-selectfield diff --git a/README.md b/README.md index 10c1c78..2104119 100644 --- a/README.md +++ b/README.md @@ -86,4 +86,15 @@ rails s email: user@example.com password: 12345678 ``` -* Search `@CoachAIBot` on [Telegram](https://web.telegram.org/#/login) \ No newline at end of file +* Search `@CoachAIBot` on [Telegram](https://web.telegram.org/#/login) + + + +* In case of server issues, as: "A server is already running. When restarting" + +Try this: + +- bin/bundle exec pumactl start -P tmp/pids/server.pid +- Wait for app to boot +- touch tmp/restart.txt +- App reboots just fine \ No newline at end of file diff --git a/app/controllers/webhooks_controller.rb b/app/controllers/webhooks_controller.rb index e145c3d..25fbbf4 100644 --- a/app/controllers/webhooks_controller.rb +++ b/app/controllers/webhooks_controller.rb @@ -9,6 +9,7 @@ def callback rescue Exception => e ap 'Rescued from:' ap e + ap e.backtrace end render json: nil, status: :ok end diff --git a/config/environments/development.rb b/config/environments/development.rb index 600634e..6dde858 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -40,7 +40,7 @@ # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. - config.assets.debug = false + config.assets.debug = true # Suppress logger output for asset requests. config.assets.quiet = true diff --git a/config/secrets.yml b/config/secrets.yml index 619f5a7..bf0f584 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -18,8 +18,9 @@ # Environmental secrets are only available for that specific environment. development: - dev_bot_token: 474840015:AAEWUooE8EecBDjYQmskZhLqdI0kaILf5Rg - bot_token: 294560170:AAFaB9cQ-hCzQEfYNr6z30gD2K7FeDZ1gVQ +# old_bot_token: 474840015:AAEWUooE8EecBDjYQmskZhLqdI0kaILf5Rg + dev_bot_token: 294560170:AAFaB9cQ-hCzQEfYNr6z30gD2K7FeDZ1gVQ + bot_token: 509838469:AAFGZo_8SgNaV2NnRiH0KKDW2smkgbK-vpc api_ai_token: 22dbf938bd724c8ebec6e0736bcf155e secret_key_base: b76119aa5db9eff7c8478773bb365ec1b87d2d5fb5412d0f7ee85517ff123facdc64d5d713267b61dfa5f443dd2b524822226772b76d33a7efee8e130ca95706 diff --git a/lib/bot_v2/dispatcher.rb b/lib/bot_v2/dispatcher.rb index 654a82c..cc2ec07 100644 --- a/lib/bot_v2/dispatcher.rb +++ b/lib/bot_v2/dispatcher.rb @@ -5,153 +5,153 @@ class Dispatcher attr_reader :message, :user - + def initialize(message, user) @message = message @user = user end - + # process the user state def process - + if @user.nil? # user needs to log in LoginManager.new(@message, @user).manage else - + # dispatch in function of user state and text input aasm_state = @user.aasm_state ap "CURRENT USER: #{@user.id} STATE: #{aasm_state}" case aasm_state when 'idle' manage_idle_state(text) - + when 'activities' manage_activities_state(text) - + when 'messages' manage_messages_state(text) - + when 'feedback_plans' manage_feedback_plans_state(text) - + when 'feedback_activities' manage_feedback_activities_state(text) - + when 'feedbacking' manage_feedbacking_state(text) - + when 'questionnaires' manage_questionnaires_state(text) - + else # 'responding' manage_responding_state(text) - - + + end - + end end - + def text @message[:message][:text] end - + def back_strings ['Indietro', 'indietro', 'basta', 'Torna Indietro', 'Basta', 'back', 'Torna al Menu', 'Rispondi piu\' tardi/Torna al Menu'] end - + def tell_me_more_strings ['Dimmi di piu', 'ulteriori dettagli', 'dettagli', 'di piu', 'Ulteriori Dettagli'] end - + def manage_idle_state(text) case text # Activities & Plans when /(\w|\s|.)*(([Aa]+[Tt]+[Ii]+[Vv]+[Ii]*[Tt]+[AaÀà]*)|([Pp]+[Ii]+[Aa]+[Nn]+([Ii]+|[Oo]+)))+(\w|\s|.)*/ ap "---------CHECKING ACTIVITIES FOR USER: #{@user.id} ----------" @user.get_activities! - + # Feedbacks when /(\w|\s|.)*([Ff]+[Ee]+[Dd]+[Bb]+[Aa]*([Cc]+|[Kk]+))+(\w|\s|.)*/ ap "---------CHECKING FOR FEEDBACK USER: #{@user.id}---------" @user.show_plans_to_feedback! - + # Messages when /(\w|\s|.)*([Mm]+[Ee]+[Ss]+[Aa]+[Gg]*[Ii])+(\w|\s|.)*/ ap "---------CHECKING MESSAGES FOR USER: #{@user.id}---------" @user.get_messages! - + # Questionnaires when /(\w|\s|.)*([Qq]+[Uu]+[Ee]+[Ss]+[Tt]+[Ii]*[Oo]+[Nn]+[Aa]*[Rr]+[Ii]*)+(\w|\s|.)*/ ap "---------CHECKING QUESTIONNAIRES FOR USER: #{@user.id}---------" @user.start_questionnaires! - + else ApiAIRedirector.new(text, @user).redirect - + #GeneralActions.new(@user, nil).send_reply("Hey there") end end - + def manage_activities_state(text) ap "---------INFORMING ABOUT ACTIVITIES USER: #{@user.id}---------" case text when *back_strings @user.cancel! - + else # when 'Ulteriori Dettagli' @user.get_details! end end - + def manage_messages_state(text) case text # Respond Later when *back_strings ap "---------USER #{@user.id} CANCELLED MESSAGES RESPONDING ACTION---------" @user.cancel! - + else ap "---------RECEIVING RESPONSE FOR COACH MESSAGE BY USER: #{@user.id}---------" @user.respond!(text) end end - - + + def manage_feedback_plans_state(text) case text when *tell_me_more_strings @user.get_details! - + when *back_strings @user.cancel! - + else @user.show_activities_to_feedback!(text) end end - + def manage_feedback_activities_state(text) case text when *back_strings @user.cancel! - + else @user.start_feedbacking!(text) end end - + def manage_feedbacking_state(text) case text when *back_strings @user.cancel! - + else @user.feedback!(text) end end - - + + def manage_questionnaires_state(text) case text when *back_strings @@ -160,7 +160,7 @@ def manage_questionnaires_state(text) @user.start_responding!(text) end end - + def manage_responding_state(text) case text when *back_strings diff --git a/lib/bot_v2/feedback_manager.rb b/lib/bot_v2/feedback_manager.rb index bfec824..6d5458f 100644 --- a/lib/bot_v2/feedback_manager.rb +++ b/lib/bot_v2/feedback_manager.rb @@ -85,7 +85,7 @@ def inform_wrong_plan end def send_activities_that_need_feedback(plan_name) - plan = Plan.where(:user => User.first, :name => plan_name).first + plan = Plan.where(:user => @user.id, :name => plan_name).first activities_names = Activity.joins(plannings: :notifications).where('plannings.plan_id = ? AND notifications.date<=? AND notifications.done=?', plan.id, Date.today, 0).uniq.map(&:name) bot_command_data = command_data bot_command_data['in_feedback_plans'] = {'plan_chosen' => plan_name, 'activities_that_need_feedback' => activities_names} diff --git a/telegram_webhook_req b/telegram_webhook_req index 2d4b9c9..ba293d9 100644 --- a/telegram_webhook_req +++ b/telegram_webhook_req @@ -1 +1,3 @@ -https://api.telegram.org/bot294560170:AAFaB9cQ-hCzQEfYNr6z30gD2K7FeDZ1gVQ/setWebhook?url=https://09ce1126.ngrok.io/webhooks/telegram_vbc43edbf1614a075954dvd4bfab34l1 \ No newline at end of file +curl https://api.telegram.org/bot294560170:AAFaB9cQ-hCzQEfYNr6z30gD2K7FeDZ1gVQ/setWebhook?url=https://76875f2c.ngrok.io/webhooks/telegram_vbc43edbf1614a075954dvd4bfab34l1 + +curl https://api.telegram.org/bot509838469:AAFGZo_8SgNaV2NnRiH0KKDW2smkgbK-vpc/setWebhook?url=https://76875f2c.ngrok.io/webhooks/telegram_vbc43edbf1614a075954dvd4bfab34l1 \ No newline at end of file From bfc9c8415e741afa9f78eb5090213b38b920702b Mon Sep 17 00:00:00 2001 From: neboduus Date: Thu, 1 Feb 2018 15:41:51 +0100 Subject: [PATCH 3/7] removes /pdf from gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 90d5308..af7dbe7 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,6 @@ !/log/.keep /tmp/* -/pdfs/* /csvs/result.csv /assets/images/profile_images From af47f400810365d736bf38e845b16b83abf668f6 Mon Sep 17 00:00:00 2001 From: neboduus Date: Thu, 1 Feb 2018 15:45:54 +0100 Subject: [PATCH 4/7] restores bot api key --- config/secrets.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/secrets.yml b/config/secrets.yml index 3f3649e..619f5a7 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -18,8 +18,8 @@ # Environmental secrets are only available for that specific environment. development: - dev_bot_token: 294560170:AAFaB9cQ-hCzQEfYNr6z30gD2K7FeDZ1gVQ - bot_token: 474840015:AAEWUooE8EecBDjYQmskZhLqdI0kaILf5Rg + dev_bot_token: 474840015:AAEWUooE8EecBDjYQmskZhLqdI0kaILf5Rg + bot_token: 294560170:AAFaB9cQ-hCzQEfYNr6z30gD2K7FeDZ1gVQ api_ai_token: 22dbf938bd724c8ebec6e0736bcf155e secret_key_base: b76119aa5db9eff7c8478773bb365ec1b87d2d5fb5412d0f7ee85517ff123facdc64d5d713267b61dfa5f443dd2b524822226772b76d33a7efee8e130ca95706 From c11d02a27049a1f80b4ce61492ed6e5159830aa5 Mon Sep 17 00:00:00 2001 From: neboduus Date: Mon, 5 Feb 2018 14:01:08 +0100 Subject: [PATCH 5/7] old changes --- .DS_Store | Bin 6148 -> 14340 bytes csvs/features.csv | 1 + csvs/result.csv | 1 + telegram_webhook_req | 2 +- 4 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.DS_Store b/.DS_Store index cb65d4661dd3dc5c8186d6db39180f4125ae0d22..3f95442ef631686f5b0a76b94677c303483485b1 100644 GIT binary patch literal 14340 zcmeHNYiw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Q8O@;t;Nqb%V{~dg&(H_ zl{eGeg0f0kRk|vhS#XB@k~;YJX#_?2SCm0j{kGlxtFmU?^pde`==%SQFr#~N_$NFr{UN8*;j$$`-fkFca^WO-&` z32&hxyIfXPb7TGH=GKngU5lJnSX-g0*GDXHD~idy8S;RL1V!}atM#f`(VHL;xc-J( zuh$s>+6EgNysC%=MLfn8Z)#Fi5fX|RjMubmQ@t`&6j2(l+S#Uh(;=e>&Uod`6{-OyRdUL{1K_Kw9AWbQoKuGU;hDpef2#kU`A8e=a;2@0CX?&jegNyJ8aR<-B zH{m6C72c#k?i~u`-i1F?F!xu?!xAi|fUcYZx_S!b8Y!6Dj(cz~1}K2L4UgbQaR84K zXAs5+g>ci3;O$fR8T>5Xk6*yA;8*csVh_HB-^TCYckyN74PM8e;?M9G_#6D4oNy+j zJCI(0l=yp+*N~fL5I(&;a%*~edn)_>hmm_#uwXepC%P@$p%S5D4c1~ilz33nvd9212eGXs5S8!2IHv`Z8>FG;}Z;-U%xrA{DQ(T?P2XMm7`DH4G zp!hbe7~#W3$9JsA`R&X8n$gb}vUHhKm%ft;NM&1y@1L{x07vg7XkgZ8ck)X3NV_?n#?|I@y>$@PHi0oMbr2V4() zkUdZ+7uUk?|Lt4({{IKr1@78h4}9o7fCb%y-Cg8{^o@gDkMO&8etO2~;W{tS!xNQ- y31#9s9!YT>k6!q7yj?=c&ZsTGizFAMq!Ok7_(j0XB^EdSr<(?D{Qn`1|NjZ`>_Z3u delta 172 zcmZoEXfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~3gIoZI3MH0wo5CvjJuv{8LCPO-d z9z!KV?#6@5nHfbV^C%>4-mMnTIB|mJW_K|c#>vaX&n;%>;1Fa6=>%%x1`@6yLpL7$ n&ODjlL{|qS3^b0R0YZbAAU+d_1_2-g 3 times a week,Low 3,23,2,Mostly moving (Involves movement more than 3days per week),1-2 times a week,Low +4,30,4,Mostly moving (Involves movement more than 3days per week),1-2 times a week,High diff --git a/csvs/result.csv b/csvs/result.csv index bdaa546..96df39f 100644 --- a/csvs/result.csv +++ b/csvs/result.csv @@ -3,3 +3,4 @@ 1,8,23,4,Mostly sitting (Involves movement less than 30 minutes per week),1-2 times a week,Medium,LOW,LOW 2,2,23,4,Mostly moving (Involves movement more than 3days per week),> 3 times a week,Low,HIGH,HIGH 3,3,23,2,Mostly moving (Involves movement more than 3days per week),1-2 times a week,Low,HIGH,HIGH +4,4,30,4,Mostly moving (Involves movement more than 3days per week),1-2 times a week,High,HIGH,HIGH diff --git a/telegram_webhook_req b/telegram_webhook_req index 3d68e22..92814de 100644 --- a/telegram_webhook_req +++ b/telegram_webhook_req @@ -1 +1 @@ -https://api.telegram.org/bot474840015:AAEWUooE8EecBDjYQmskZhLqdI0kaILf5Rg/setWebhook?url=https://910ca535.ngrok.io/webhooks/telegram_vbc43edbf1614a075954dvd4bfab34l1 +https://api.telegram.org/bot294560170:AAFaB9cQ-hCzQEfYNr6z30gD2K7FeDZ1gVQ/setWebhook?url=https://5521d08d.ngrok.io/webhooks/telegram_vbc43edbf1614a075954dvd4bfab34l1 From 5bdacfbb3726ba5ee6b97ef1f736c713087ecbd1 Mon Sep 17 00:00:00 2001 From: ahmed fadhil Date: Wed, 7 Feb 2018 18:29:11 +0100 Subject: [PATCH 6/7] merged development --- Gemfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index bb137fc..ece05b0 100644 --- a/Gemfile +++ b/Gemfile @@ -124,10 +124,9 @@ group :development, :test do gem 'selenium-webdriver' # Use sqlite3 as the database for Active Record #gem 'sqlite3' -<<<<<<< HEAD -======= +# <<<<<<< HEAD ======= gem 'pg', '0.20.0' ->>>>>>> c11d02a27049a1f80b4ce61492ed6e5159830aa5 +# >>>>>>> c11d02a27049a1f80b4ce61492ed6e5159830aa5 gem 'railroady' end From d6e50140a8bc3a819b9e71515b8d32fccf60203d Mon Sep 17 00:00:00 2001 From: ahmed fadhil Date: Wed, 7 Feb 2018 18:35:15 +0100 Subject: [PATCH 7/7] new branch for UI front end --- Gemfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile b/Gemfile index ece05b0..5dc33b7 100644 --- a/Gemfile +++ b/Gemfile @@ -65,8 +65,6 @@ gem 'awesome_print' # Authentication solution gem 'devise' - - # Use Puma as the app server gem 'puma', '~> 3.10.0'