From ea357e75bff9757a6d9fe511cac86bf2766c074b Mon Sep 17 00:00:00 2001 From: Matthew Rider Date: Wed, 20 Nov 2024 21:06:55 +0100 Subject: [PATCH] Allow configuration of WhatsApp quick reply button text (#2079) --- Gemfile.lock | 16 +- .../inventories/staging/host_vars/staging.yml | 255 +++++++++--------- .../three_sixty_dialog_inbound.rb | 9 +- .../three_sixty_dialog_outbound.rb | 3 +- .../whats_app_adapter/twilio_outbound.rb | 2 +- .../admin/organizations_controller.rb | 28 +- app/dashboards/organization_dashboard.rb | 7 +- app/models/organization.rb | 4 + ..._add_whats_app_columns_to_organizations.rb | 10 + db/schema.rb | 4 +- .../three_sixty_dialog_outbound_spec.rb | 7 +- .../process_webhook_job_spec.rb | 9 +- spec/requests/whats_app/webhook_spec.rb | 2 +- spec/system/admin/organizations_spec.rb | 2 + 14 files changed, 178 insertions(+), 180 deletions(-) create mode 100644 db/migrate/20241120182931_add_whats_app_columns_to_organizations.rb diff --git a/Gemfile.lock b/Gemfile.lock index f52d8ead6..3744b362d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -82,12 +82,12 @@ GEM activerecord (>= 6.0, < 7.1) addressable (2.8.1) public_suffix (>= 2.0.2, < 6.0) - administrate (0.18.0) - actionpack (>= 5.0) - actionview (>= 5.0) - activerecord (>= 5.0) - jquery-rails (>= 4.0) - kaminari (>= 1.0) + administrate (0.20.1) + actionpack (>= 6.0, < 8.0) + actionview (>= 6.0, < 8.0) + activerecord (>= 6.0, < 8.0) + jquery-rails (~> 4.6.0) + kaminari (~> 1.2.2) sassc-rails (~> 2.1) selectize-rails (~> 0.6) administrate-field-active_storage (0.3.8) @@ -204,7 +204,7 @@ GEM image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - jquery-rails (4.5.0) + jquery-rails (4.6.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) @@ -499,4 +499,4 @@ RUBY VERSION ruby 3.0.0p0 BUNDLED WITH - 2.5.21 + 2.5.22 diff --git a/ansible/inventories/staging/host_vars/staging.yml b/ansible/inventories/staging/host_vars/staging.yml index aa9cb3b00..2744dc670 100644 --- a/ansible/inventories/staging/host_vars/staging.yml +++ b/ansible/inventories/staging/host_vars/staging.yml @@ -1,127 +1,130 @@ $ANSIBLE_VAULT;1.1;AES256 -33626661323666343763646635633231633165336132393834346634663034636230633137663366 -3036316261643861653538653338633438333238366338640a323833643335363139653433353237 -39396337386264326463313832643631333738646638633761623033343230363462613732383664 -3535333430636662660a313164353631306562643331306563343533303233313634363263383531 -62623832346434613732396566663363393535653637333063623662313766333739373962316562 -65653035373762613534343537343834373362616635656164343238333032623235613535323836 -32353463626638646163313739326236613130306235386361306232373761623735313938303031 -33373938383261326138393839333436373831633331613861393134653962663939633134336462 -66643136376635616437313339323964633135386339313439376231336537393562393662363263 -63363237393333303763386539303638353531626432343764623161393830343664663038663935 -33373632333732623366386163323265633839373537666333386335383964346164626466663838 -37356134636236393732376235653931336364373461336339616632623939353964623434323232 -63643934313661386230633337383936383636323535343661336335343062323266316139623364 -35653965323362343439653731343463333664363166383531653061353438623663346562376330 -31353139376463366436616362343266623936343638343163623961376139366134643666373734 -31333334636463306532616464313539613639636130306261626334636338613062343261396561 -64616133353734653238373965663431663438346564366335656233656132643335346636363537 -66663530313032326135313962343033376166616361656534323437633237643336663230343264 -65333062326535373433333431323564653831376536313037363366333062396231656362396432 -64646331656530666264343335633865393333393532313836643639343539616333623135346562 -33393732343365646265323131643935613061656565633231363861343036393730383661636164 -62333031653037373561343464623833636366643535363031383234653362666566376432303063 -38366361653034333631376264306430623237653835306639336633636138653736346137386137 -39373134643362393263333437356237616538393761633435353665626238313135306334336138 -38366362636331366663663763323134396136643232383732623664656632613661316538393630 -34346138366530353564653330343833396630396135633439396166636239366239656361336339 -62663664613733383462366632393063373262636665393337616564363436373737356136653164 -63663861636634323465646436333236393633626234336230633436653165343330323663626363 -62626462643666373135323637343032643738323033363361363830386166313339393331313630 -62346630626333376330323030663434333861366339376539636161323037336666643534336435 -32656636643061376538653265626236353163353131633661316339353334343230356466346637 -61376138613937373432396364396665366164373064383063626565346235313635663661396433 -61613162633431386638363637313861366635643836343430383936613966306134663563346265 -33633365653330366634376130323036323163613366376665666234613964323831633938633430 -63333261306439613831633763663434616337393531346238383734323861336339313330353235 -65616266636330316330393461323564363061663862326465626463383538356531376564313831 -39626163353231646234613438643961653231616137313161323439303738393638336137313533 -34613764373363343662356332303835393836373938376235316263626239663535393866373361 -34643565616439643632316232393338333163666439363835616365626434633239303936333830 -36303237633837336464303333333661653334323364323561356234643465363435613434326133 -61323063653033366132646236636538313137323630343965633030363565376330373761373635 -31386630326631383566666539623538333061396433326530303366613634323331343437336366 -37633962643233653333643537643738363961353861393066366265663331393138313739336465 -30653839306163643165373765353930333765656539393332393563613537343631366436383561 -64383232616339646435643462303065323863303939396561653233323164313638643530633332 -62393135646139623235353336373930323462313030636535303066356633366633346261363064 -30323036363331356234333332313932353265336236333061383565333033393961636335326534 -34646339306431386163396333623165656333623061623134353030313965396434653034663466 -63373763303231353364383633623334626334366438306433343765386666633965323937353361 -33373138363937626438313339383064306136396566303936303831373131396332353966326430 -32313237343634303066353634326436393935636562326262653833373030376539303861666361 -61663637636631663937613331356538646165396531386237313264633030636630383038376238 -30643432623262653937613564336438383537633764333530343938383036303762663963353236 -34323563666634316664613435353961336361613038383961626334323664636438643163383330 -32613139343830393133356263663332363634383139666262663736636638306534343034623764 -34633536396538333339626139636237386438366435386563633966393239336638356461396434 -64623934643938646231646134616361356430613164306434636534636161393031343939363931 -64363664313231663161336634633664383566393165653235393332616262333063613038353533 -62373665646236323234636661373239613366303939643334343734343130643738313236633831 -34363661623536313963356366626138346432333065663465646232653931366630323434313731 -38303065306637353566636630653765313436326139633532333331393063306233323633343762 -32356133383131663831373231356230373739663562666165663336383265346636343638633437 -34363762396534393237653235666133303530303736653962353932373766653864613236383037 -39656333383131386363393238663134373464366264393035363036343466643938353732616262 -32313561626265323735353066663034336366353362323965306665343332623362363063376634 -61656338623765663864333431643333373032623134656437643836643462656364613032396366 -63316663353739333135303435323938383333353632383861323761383339303131376164663061 -33636339663065383039623564613230663465306433633564383861643931373632613162356164 -61313165323734616263643366333661663564623966386665626334316437383332393464393839 -31653766646331623635396531363865323437303764376336333165666564383764653336323436 -61366138373661613865376233653165316632653435316463326330636337666236373062323261 -66353131366138306239306362366334306362303137633864656538373036343164353962643065 -64656638653466346636643063366139626137363032396465303039626430306438336638623336 -37313062316261346636386662313138653031306239656636653063303564343332303436633264 -36353965393165666532313931373761653537633264353338343135643964383137643433376438 -35633930633634613930633734643232373538383766343733643962663738646135393832383365 -34613338646637616663633731626536383066353537356436393664333562313636656262313339 -64643265363032313132343764346236353938656430633265303038346439313465666664343731 -31343137383237346330353161316430393261613834653266303133343962633433353030633835 -65313966383732343235663939643362393630643935663361373434363235623938633061363731 -62393735653864613361383236653261356666366635333732633232313538393464626531333064 -66333531663565323333326166616436663838323832353733353261653966333330623861343366 -35373735333033346235386539303431366362653033653632363464363961666237373938353964 -66373030616265356335383164626566646537613532633736653538366130653964663732396139 -33613265333139303538373835383239623766666430663736376639653935653938613363623764 -35666365343635633238626135366230313134323537633666646634633531326162353930313230 -31303634663035343164306464646230386238386363383439376237333336353132306339626264 -31303032383532633130623031616632666165633332626531376536643132316532326162303563 -66363139333766633330376339333461383936323931386165666334333239653635383933303462 -33623863336337373530363962666331323533333934626266376335663762376533343030376135 -39393664623235323661363831653939666636393965663564356530316435653564656638376333 -33316539616230373361623966386362333631663430363836383838646238313563353837326237 -61303662383438653962383566383430643664363565333133613364646532343733316237653865 -66653236316466396266363739393561346339383565393630633633363265353664393338336162 -34613435616563373164383330613261623239353539636231616561343865626132336361376363 -37323030353363373735613231303631356338396534376631303566343563353139303766633239 -31623735336465393864393766333863343566326565633634343237623633656462663064323133 -32333566333531646635383530653965353966353130636262613539323435663930323064326263 -36336130306534646437363032323237353538323032363633663335613361336361653536356633 -38363734323962623039626661326666316530303061346437323563383535636432343432643333 -36346563663532376435343631323165356531613464623062613034643239303635653732383138 -64346532363332336138626535653637653632633238376230366362313863316536393763313865 -36386366333564376263346265633139643166646466663930366639353332666365636662346638 -38663831653064623464316536393164386239376439376335333039336631323135623231366238 -62633433386364653231656462643430356461323063646263386463633163303564623132616531 -38616435663038383162393436333639326535323534626533383231306338653865373361653538 -34316235626639353937636435393837666661336630393638373133323964303136313635656636 -33346363316135626465643234636337386562303664326234643238353961633533303335333162 -66363332633263626132306535303632336233366636626330333162313033643666303539393262 -62653064393033636561663837656664373537653364333830383436376636626138313735613638 -34346233323564326466653762316566356562663237623736636230333862366130613732336264 -34323161313838343761316361353464663031353961353138353636366566353432653766626133 -35366338623064616164666336396634366533343934303131613736363132396563303138636330 -39326338363065643531666630353738393937326133373332333330393365306430303933353034 -33623533303661336231393662393563663331316539613937316663666466323663313933353838 -62383462646662386137666333356461353036393031633736643138613032663466343361316363 -65636563353161373662303963306366623032616465613531383361396361303065656437633639 -37353864626234633762303235343033386435653665363938373866336536666434653563363032 -33616262636535356661356664326165643665643763316164373962303134323134653563623331 -66633739646433356164373962303830613235316362376465663636633538636334613836393334 -35633932383533646463623734383833336163636233633564313639656364623937613665303135 -30316165646531656435396533303962333231343161376264633438653862393262303232306466 -38396564666533383161613164383635363339393136366536383332653965633330326138346265 -31663930366533393931623339623865383636636139646235316263376539333139373863323839 -33393363346436393738326666393330383331663231623164643937643535306564633330393531 -3838623066343038396332363965633138333231396431336566 +63613537376531363935303532396431373465303466343538636634346464616130303833373066 +3965633162373435393735633433633663376333333035320a333533616535303563366263613063 +35653265633763396633666265663134333630623338323865393163306361316637366136666361 +6166353361363766640a343263313332383138306237663937383738393334323137313861323063 +37646433623263643931623461633566653933303662333234356666333639333734643430373665 +31653261666664326364306536666638663939323637313435396630656463633466623566373465 +66663763613239306666336331383631306634663136653766376633663433393039623663323462 +62653362636230663131666330303938303839613938393836363861623563313832623535323563 +37303631363330323463383535303534646664366666623337326438656336323063373362666564 +33393164663234623361326234666639316334356639316239653263396463633034373061396437 +30653162356437316265633837636165623333336638623361326436663937396131363561656233 +31333733343061313832373065376265623239383732663638373531316336356333373134393835 +64343933613663653638336639323134396262363930303039306163653231616463333632663638 +34303236373339643863343165383064626333346333623433343132613639623538353165386166 +34396339336338353763643634646435356337663236396666623132643836373532613931313064 +63656462643738346430663463663234306334356262343263346664636130636530616132666534 +33326462646333623635386338363064613735393263333534643433633562656638376132376365 +31643232356661623639306436366364356437343761653833656539373935666665316165373231 +39313537356436366264656262386130366438323765306565346535613265313861353530656638 +62643839323266313931613536363264393038373339623435633939626436633135653561633730 +66663235643637343862376536326664363432333966353839303331306165393039306533336364 +36346438663533643065383231653738396330376463373933636566646561636538653131633131 +66643139613732323134366631653035656333633435323435613766326530663532313966653032 +62383633336331323163326566626539613030316439653762383962303766643161393639343861 +32303462333432333665613364653938626662626165363366326435313465303934346634393561 +38396135613534393033353036393131363338363766323561363766623963343233336666343131 +37323639623535623235643063343537646531303232383262616237396166303164613436353465 +32376637353932626332666137663438333833663264643530336363343331613838643435323361 +37643333633933373733396134363165393033373233316237396535636130636263666434646337 +35343634326432313434323863636363306435373364336464656438356532663661666638343333 +32366230666261633034386536633066336439343263316366336464646633323963646130333961 +61623639656135346163343634353663623734613561353461623433373737346663623336336237 +31376262363630363033666538353130386462626161353539646566636635623337306137373162 +37623531623838333663353439633036646334323431613165383565336332383961376364633964 +35396537643130633535626336346139633630663734326231386661613863356663326562306237 +61633535353863656435643237356330373665303336323164333366323461653030326664613031 +38393636626637336336623634316232376237393830316434343135366662613836653462623932 +65666366323962633337663464626638613932316165353361663335643835633835303565666133 +65643836383734323761383336313364646338626131326562653830313836326166373937393164 +62353931343832333561363837636538313637363636316536313436366563636664636661393136 +63613861356534343135633330643136633561306139376362353135306665383663643364393831 +63323837356634363737393133633635663562663334656365633735373838623461636339323362 +36633830633131653665626331376234393866386239323032353932386237333831633735653234 +62653366653532623362373739313331643738393664323437316536343636316361363537666631 +64633437613766653761396236386631303039656261663736653838343937336664373663396334 +38383031323937323932356334376438326532633932353661313465353537626637666334393236 +35613930346431333038653235623861393435363234653364363466373539653239663463666230 +32376332313230336232383761313238346562623739303161356461613561653661623238376134 +35323530313861353161383864366564316137383664633130353136343664636133346633396561 +63626365626563353834623234386436356638383431313965303739373237386161643364343939 +30393866306362383661623731393434373338353832393237613936643631393636383233316163 +31626266336232336433656638323066613038633237376538353333633037643336373235653334 +38346438646537626563643365386330613466353237663432383235663863623734643364396636 +30613530633835343062663863646137353264623962333365343437636165363534313235306636 +38386438636132663733343364346363373065346364623938656333366633663232616137366639 +62333461333835353562316264333265366462613439313230343464643531303730663161326566 +37623639636163326532646431356639626634613664663266626134363665383331393030336538 +66646165373135343231383438313638653761386137643064316562663636626662373934353466 +38626632386533333666363333376435306561363561323232313664633935316163333965656230 +65366262636563363833373066336536633435666465633633326366393461386262376538663563 +62663639343061363836643762383839376532366334313562353066653539323036353865353738 +31646265633436616239306430343763326465653363336536383936316137323536386263376232 +32303639643130386466343761353930326433363137666232666437393039393233616162396466 +33303162646564363262623630303866623066663863313837636465383236373534333962373963 +63316437396336663033626465343132386461393237623766336137346263646365393233613738 +65653333396634323033353131633334626564373232643730313030333832346537666239653132 +37643763306562616338363331356538313533633361373332353161343239636330633037666663 +36366262346530646139313765316535653837313336663834613965383734626630663766613862 +30313333383163346136366631333139313838663261343938366663353431376666636564643434 +38313137613563663636643933323030373164353538326266303136363835653539366562303630 +36646264323339623766323730366564373938646631393863643537343765363965636637653233 +38316561656631306634383135366331643930643961373535303231666263623932396663346132 +65613039343337663763666565626432336439303263333063353135616163313637633032633461 +33363737366637396637303138653532303836336163333236303964376233643462636430383463 +35653166373964656561303730623339623537366138313634363663666536396331373333656239 +64663731376533626530366339316461633361373731343637356463393465633735613937343635 +34363961346130653437313266623061336466366665333939613235373635636431333538363639 +63643765383439306565323832363764643163643038653666666233643862376261383163386636 +31393635373662613462366436623639393665346465383339303066336461326165636666643661 +32613031313730356665373665333762663165633635373839386238353965653063363265303264 +65633832646233383935316361643463623563636237316634346239323430636538323235373238 +38323538386437653665653961333436323130373533303836376261383632306334393934663631 +65616466393134306435373438353262316433653062336162326634366637643237633732366337 +66666435346562663630646238613831353866306533363839313562306134663337373562663839 +64626264363335653734336663616364373764303965346333396533363663346166313434343264 +63353339663063353562663432333465326164623636636438333239376331323865313166613137 +66396261376563643039643030323166623833316136323439613836336137333634613861626138 +64653733653331396637333030633430623633376431613138383934366165383239643265383266 +39393330653365316233316235366366396566316563353531303239336132386465663236616162 +61663635313763613431326361363734336431313235626634636631343033373035313236656663 +62626665366530333537363334313966633632636330613861383530386336353239333563633265 +35313535333564626562316266393965376666613138376339373264316561316262333034643665 +66636361346161353531383131353137626533373462303762643464623635656362636266383538 +33323932653638343166303062376431656463383535303161333137623037366535383463333932 +64646336653939336535386262313366383732326432316662366466363161316335343866656563 +36343664303265663762333937343833353733366262326461333764316632386535666365326661 +35616533646436386432343237313637383735643361346631373535623765623738643261393532 +39633635633166663533346263666666666264623933633463313135653466623366396233343132 +33326535623133303532646136353766393630393932633833656130633431363934393030636439 +32353832636639333164626665386166363631656561336566636534616564316566336233323536 +30386166336434303033306465353265386265376536363965363036356538323634616334663935 +64366236316163333332343836316337336538616439393765633436383466366635623963313339 +37323839373833356539323731623365643934373461326135646161636565393430666663623939 +65613565356633383264343430613464643166636235643536626233616431633839623261313431 +33613035626233386663333330353866653266343032313965633637666162393365313134333263 +34366561353264383935633631353532303264626163353737396262303961313664313165633934 +33393134343832373534313464376161313835363835303063356363316432326333366630333437 +37643431303862353533386132323565316131323433363461303032326263636634353462353835 +34366233333032663065303935306166626334386338613635353336396165666133636531663535 +34383538643263383366313561323233373761613164633833386461333939323964386639373530 +34636335353666636261343537623839306435373465386336346235653835656237613537306666 +32333336656238613161303835613336646462363735343132653165313766373434303632633264 +31383636666637366637636563643231613533363832653735333666363838323432383835363431 +63616466616663346562303664613463346265323530376530326432646633666664646465396239 +65663636326631613866623063653330343433326266366565383438396262313864323032336230 +66646262346232336162663134393434333839336337366166396565333735633062306239663935 +38633863373137336234346338333564643634336139653733613033656233396461646436316663 +30303232343537666331333239653765326166613633623235353734616138343235613431633061 +63643837653134373161393038653834363862326563653261633761313236636133663837666266 +61656634353432616139313261306532333939303964666333363939373631356138626138363636 +62643261663930663464323232333837663534393833326663396561383864333861326163373532 +33376639663865646561386630616230356566353762353630333862336164383330663931316330 +61666539313333346238373536396666383963663935613731643738383838663538616364663836 +33343335326139353939366464396533363834643231613137323031623661376136323631333638 +30363830346464643434303366363961643639353330346163313330643438663334326432393362 +38323362626135316163626337333562373639326666363066303261383237313762613335363030 +62356230383234616634653863373337373065313764356139323132353864333735333334613537 +37343065386137366662323066326333656131363238613961366366373561633466626361653939 +64643834316438396430306332636231336661306137623637343633396530653933 diff --git a/app/adapters/whats_app_adapter/three_sixty_dialog_inbound.rb b/app/adapters/whats_app_adapter/three_sixty_dialog_inbound.rb index f473aa430..999e65ced 100644 --- a/app/adapters/whats_app_adapter/three_sixty_dialog_inbound.rb +++ b/app/adapters/whats_app_adapter/three_sixty_dialog_inbound.rb @@ -140,7 +140,7 @@ def error_indicating_unsupported_content(errors) def request_for_more_info?(text) return false if text.blank? - text.strip.eql?(I18n.t('adapter.whats_app.quick_reply_button_text.more_info')) + text.strip.eql?(organization.whats_app_quick_reply_button_text['more_info']) end def request_to_receive_message?(contributor, text) @@ -150,12 +150,7 @@ def request_to_receive_message?(contributor, text) end def quick_reply_response?(text) - quick_reply_keys = %w[answer more_info] - quick_reply_texts = [] - quick_reply_keys.each do |key| - quick_reply_texts << I18n.t("adapter.whats_app.quick_reply_button_text.#{key}") - end - text.strip.in?(quick_reply_texts) + text.strip.in?(organization.whats_app_quick_reply_button_text.values) end def unsubscribe_text?(text) diff --git a/app/adapters/whats_app_adapter/three_sixty_dialog_outbound.rb b/app/adapters/whats_app_adapter/three_sixty_dialog_outbound.rb index 2e425f3cd..b27fdeaa5 100644 --- a/app/adapters/whats_app_adapter/three_sixty_dialog_outbound.rb +++ b/app/adapters/whats_app_adapter/three_sixty_dialog_outbound.rb @@ -41,10 +41,9 @@ def send_unsupported_content_message!(contributor, organization) def send_more_info_message!(contributor, organization) return unless contributor_can_receive_messages?(contributor) - text = [organization.whats_app_profile_about, "_#{I18n.t('adapter.shared.unsubscribe.instructions')}_"].join("\n\n") WhatsAppAdapter::ThreeSixtyDialogOutbound::Text.perform_later(organization_id: organization.id, payload: text_payload( - contributor, text + contributor, organization.whats_app_more_info_message )) end diff --git a/app/adapters/whats_app_adapter/twilio_outbound.rb b/app/adapters/whats_app_adapter/twilio_outbound.rb index 60bc2fa95..b77a25d50 100644 --- a/app/adapters/whats_app_adapter/twilio_outbound.rb +++ b/app/adapters/whats_app_adapter/twilio_outbound.rb @@ -33,7 +33,7 @@ def send_unsupported_content_message!(contributor, organization) def send_more_info_message!(contributor, organization) return unless contributor_can_receive_messages?(contributor) - text = [organization.whats_app_profile_about, "_#{I18n.t('adapter.shared.unsubscribe.instructions')}_"].join("\n\n") + text = [organization.whats_app_more_info_message, "_#{I18n.t('adapter.shared.unsubscribe.instructions')}_"].join("\n\n") WhatsAppAdapter::TwilioOutbound::Text.perform_later(organization_id: organization.id, contributor_id: contributor.id, text: text) end diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index d12e81a0f..3c1f02835 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -1,31 +1,5 @@ # frozen_string_literal: true module Admin - class OrganizationsController < Admin::ApplicationController - def update - organization = Organization.find(update_params[:id]) - organization.business_plan.update(valid_from: nil, valid_until: nil) - business_plan = BusinessPlan.find(update_params[:organization][:business_plan_id]) - business_plan.update(valid_from: Time.current, valid_until: 1.year.from_now) - organization.upgraded_business_plan_at = - (Time.current if business_plan.price_per_month > organization.business_plan.price_per_month) - if organization.update(update_params[:organization]) - redirect_to admin_organization_path(organization), flash: { success: 'Organization was successfully updated.' } - else - render :edit, status: :unprocessable_entity - end - end - - private - - def update_params - params.permit(:id, - organization: %i[id business_plan_id upgrade_discount contact_person_id name - threemarb_api_identity twilio_account_sid onboarding_allowed - onboarding_data_protection_link onboarding_data_processing_consent_additional_info - onboarding_imprint_link onboarding_ask_for_additional_consent - onboarding_additional_consent_heading onboarding_additional_consent_text - channel_image about signal_complete_onboarding_link]) - end - end + class OrganizationsController < Admin::ApplicationController; end end diff --git a/app/dashboards/organization_dashboard.rb b/app/dashboards/organization_dashboard.rb index 1f326eeec..35d5d626b 100644 --- a/app/dashboards/organization_dashboard.rb +++ b/app/dashboards/organization_dashboard.rb @@ -28,8 +28,10 @@ class OrganizationDashboard < Administrate::BaseDashboard onboarding_additional_consent_heading: Field::String, onboarding_additional_consent_text: Field::String, channel_image: Field::ActiveStorage, + whats_app_more_info_message: Field::Text, whats_app_profile_about: Field::Text, - signal_complete_onboarding_link: Field::Url + signal_complete_onboarding_link: Field::Url, + whats_app_quick_reply_button_text: Field::JSONB }.freeze COLLECTION_ATTRIBUTES = %i[ @@ -48,6 +50,7 @@ class OrganizationDashboard < Administrate::BaseDashboard created_at updated_at upgraded_business_plan_at + whats_app_more_info_message ].freeze FORM_ATTRIBUTES_EDIT = %i[ @@ -56,6 +59,7 @@ class OrganizationDashboard < Administrate::BaseDashboard business_plan upgrade_discount whats_app_profile_about + whats_app_more_info_message onboarding_data_protection_link onboarding_data_processing_consent_additional_info onboarding_imprint_link @@ -65,6 +69,7 @@ class OrganizationDashboard < Administrate::BaseDashboard onboarding_allowed channel_image signal_complete_onboarding_link + whats_app_quick_reply_button_text ].freeze COLLECTION_FILTERS = {}.freeze diff --git a/app/models/organization.rb b/app/models/organization.rb index 0a8ec781c..44b6adbac 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -39,6 +39,10 @@ def onboarding_allowed=(value) self[:onboarding_allowed] = value.is_a?(String) ? JSON.parse(value) : value end + def whats_app_quick_reply_button_text=(value) + self[:whats_app_quick_reply_button_text] = value.is_a?(String) ? JSON.parse(value) : value + end + def whats_app_configured? twilio_configured? || three_sixty_dialog_configured? end diff --git a/db/migrate/20241120182931_add_whats_app_columns_to_organizations.rb b/db/migrate/20241120182931_add_whats_app_columns_to_organizations.rb new file mode 100644 index 000000000..a8d0112dd --- /dev/null +++ b/db/migrate/20241120182931_add_whats_app_columns_to_organizations.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class AddWhatsAppColumnsToOrganizations < ActiveRecord::Migration[6.1] + def change + change_table :organizations, bulk: true do |t| + t.jsonb :whats_app_quick_reply_button_text, default: { answer_request: 'Antworten', more_info: 'Mehr Infos' } + t.string :whats_app_more_info_message, default: '' + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 41a6f75f7..c52ca04e7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2024_11_19_084424) do +ActiveRecord::Schema.define(version: 2024_11_20_182931) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" @@ -234,6 +234,8 @@ t.jsonb "onboarding_allowed", default: {"email"=>true, "signal"=>true, "threema"=>true, "telegram"=>true, "whats_app"=>true} t.jsonb "twilio_content_sids", default: {"new_request_day1"=>"", "new_request_day2"=>"", "new_request_day3"=>"", "new_request_night1"=>"", "new_request_night2"=>"", "new_request_night3"=>"", "new_request_evening1"=>"", "new_request_evening2"=>"", "new_request_evening3"=>"", "new_request_morning1"=>"", "new_request_morning2"=>"", "new_request_morning3"=>""} t.string "signal_complete_onboarding_link" + t.jsonb "whats_app_quick_reply_button_text", default: {"more_info"=>"Mehr Infos", "answer_request"=>"Antworten"} + t.string "whats_app_more_info_message", default: "" t.index ["business_plan_id"], name: "index_organizations_on_business_plan_id" t.index ["contact_person_id"], name: "index_organizations_on_contact_person_id" t.index ["telegram_bot_username"], name: "index_organizations_on_telegram_bot_username", unique: true diff --git a/spec/adapters/whats_app_adapter/three_sixty_dialog_outbound_spec.rb b/spec/adapters/whats_app_adapter/three_sixty_dialog_outbound_spec.rb index 87c20572b..334aa71b7 100644 --- a/spec/adapters/whats_app_adapter/three_sixty_dialog_outbound_spec.rb +++ b/spec/adapters/whats_app_adapter/three_sixty_dialog_outbound_spec.rb @@ -5,7 +5,9 @@ RSpec.describe WhatsAppAdapter::ThreeSixtyDialogOutbound do let(:adapter) { described_class.new } let(:organization) do - create(:organization, project_name: 'Great project') + create(:organization, + project_name: 'Great project', + whats_app_more_info_message: "We're cool, but if you want to unsubscribe, write 'unsubscribe'") end let!(:message) do create(:message, :outbound, text: '360dialog is great!', broadcasted: true, recipient: contributor, @@ -210,8 +212,7 @@ end before do - text_payload[:text][:body] = - [organization.whats_app_profile_about, "_#{I18n.t('adapter.shared.unsubscribe.instructions')}_"].join("\n\n") + text_payload[:text][:body] = organization.whats_app_more_info_message end it { diff --git a/spec/jobs/whats_app_adapter/three_sixty_dialog/process_webhook_job_spec.rb b/spec/jobs/whats_app_adapter/three_sixty_dialog/process_webhook_job_spec.rb index d4ec33340..e1fa72b0b 100644 --- a/spec/jobs/whats_app_adapter/three_sixty_dialog/process_webhook_job_spec.rb +++ b/spec/jobs/whats_app_adapter/three_sixty_dialog/process_webhook_job_spec.rb @@ -8,7 +8,10 @@ subject { -> { described_class.new.perform(organization_id: organization.id, components: components) } } let(:organization) do - create(:organization, three_sixty_dialog_client_api_key: 'valid_api_key') + create(:organization, + three_sixty_dialog_client_api_key: 'valid_api_key', + whats_app_quick_reply_button_text: { answer_request: 'Mehr Infos', more_info: 'Über uns' }, + whats_app_more_info_message: "Please do not unsubscribe. Unless you want to. Then send a 'unsubscribe'") end let(:components) do { @@ -180,9 +183,9 @@ context 'request for more info' do before do components[:messages].first.delete(:text) - components[:messages].first[:button] = { text: 'Mehr Infos' } + components[:messages].first[:button] = { text: 'Über uns' } end - let(:text) { [organization.whats_app_profile_about, "_#{I18n.t('adapter.shared.unsubscribe.instructions')}_"].join("\n\n") } + let(:text) { organization.whats_app_more_info_message } it 'marks that contributor has responded to template message' do expect { subject.call }.to change { diff --git a/spec/requests/whats_app/webhook_spec.rb b/spec/requests/whats_app/webhook_spec.rb index b568a2320..b1570fdb4 100644 --- a/spec/requests/whats_app/webhook_spec.rb +++ b/spec/requests/whats_app/webhook_spec.rb @@ -198,7 +198,7 @@ context 'request for more info' do before do params['Body'] = 'Mehr Infos' - organization.update(whats_app_profile_about: 'Here is more info') + organization.update(whats_app_more_info_message: 'Here is more info') end let(:more_info_job_args) do { diff --git a/spec/system/admin/organizations_spec.rb b/spec/system/admin/organizations_spec.rb index fb249bc8f..3bced946b 100644 --- a/spec/system/admin/organizations_spec.rb +++ b/spec/system/admin/organizations_spec.rb @@ -12,10 +12,12 @@ click_on 'Edit' fill_in 'Name', with: 'Real name' + fill_in 'Whats app more info message', with: 'More info. Unsubscribe?' click_on 'Update Organization' expect(page).to have_text('Organization was successfully updated.') expect(page).to have_text('Show Real name') + expect(page).to have_content('More info. Unsubscribe?') end end end