|  | 
 |  | 
 | 
												
													
														| 55 |          $healthNickname = $request->healthNickname; //暱稱
 | 55 |          $healthNickname = $request->healthNickname; //暱稱
 | 
												
													
														| 56 |          $healthGender = $request->healthGender; //性別
 | 56 |          $healthGender = $request->healthGender; //性別
 | 
												
													
														| 57 |          $healthGenderRole = $request->healthGenderRole;//性別 male or female
 | 57 |          $healthGenderRole = $request->healthGenderRole;//性別 male or female
 | 
												
													
														| 58 | -        
 |  | 
 | 
												
													
														| 59 | -        $survey_fill_content = ["healthAction" => $healthAction, 
 |  | 
 | 
												
													
														|  | 
 | 58 | +
 | 
												
													
														|  | 
 | 59 | +        $survey_fill_content = ["healthAction" => $healthAction,
 | 
												
													
														| 60 |                                  "healthTopic" => $healthTopic,
 | 60 |                                  "healthTopic" => $healthTopic,
 | 
												
													
														| 61 |                                  "healthStatus" => $healthStatus,
 | 61 |                                  "healthStatus" => $healthStatus,
 | 
												
													
														| 62 |                                  "healthAdapt" => $healthAdapt,
 | 62 |                                  "healthAdapt" => $healthAdapt,
 | 
												
											
												
													
														|  | 
 |  | 
 | 
												
													
														| 73 |              }
 | 73 |              }
 | 
												
													
														| 74 |              $statusCode = $this->botActionsSend($lineUserId,$clearAction);
 | 74 |              $statusCode = $this->botActionsSend($lineUserId,$clearAction);
 | 
												
													
														| 75 |          }
 | 75 |          }
 | 
												
													
														| 76 | -        
 |  | 
 | 
												
													
														|  | 
 | 76 | +
 | 
												
													
														| 77 |          //準備將填寫內容過API寫入 botbonnie 後台
 | 77 |          //準備將填寫內容過API寫入 botbonnie 後台
 | 
												
													
														| 78 |          $buildActions = [];
 | 78 |          $buildActions = [];
 | 
												
													
														| 79 |          array_push($buildActions, $this->buildActionsRequest("addTag", $healthAction));
 | 79 |          array_push($buildActions, $this->buildActionsRequest("addTag", $healthAction));
 | 
												
											
												
													
														|  | 
 |  | 
 | 
												
													
														| 83 |          array_push($buildActions, $this->buildActionsRequest("addTag", $healthThought));
 | 83 |          array_push($buildActions, $this->buildActionsRequest("addTag", $healthThought));
 | 
												
													
														| 84 |          array_push($buildActions, $this->buildActionsRequest("addTag", $healthAge));
 | 84 |          array_push($buildActions, $this->buildActionsRequest("addTag", $healthAge));
 | 
												
													
														| 85 |          array_push($buildActions, $this->buildActionsRequest("addTag", $healthGender));
 | 85 |          array_push($buildActions, $this->buildActionsRequest("addTag", $healthGender));
 | 
												
													
														| 86 | -        if($healthGenderRole != "")array_push($buildActions, $this->buildActionsRequest("saveParams", $healthGenderRole, "demographics", "gender"));       
 |  | 
 | 
												
													
														|  | 
 | 86 | +        if($healthGenderRole != "")array_push($buildActions, $this->buildActionsRequest("saveParams", $healthGenderRole, "demographics", "gender"));
 | 
												
													
														| 87 |  
 | 87 |  
 | 
												
													
														| 88 |          $statusCode = $this->botActionsSend($lineUserId,$buildActions);
 | 88 |          $statusCode = $this->botActionsSend($lineUserId,$buildActions);
 | 
												
													
														| 89 |          if($statusCode == 200){
 | 89 |          if($statusCode == 200){
 | 
												
											
												
													
														|  | 
 |  | 
 | 
												
													
														| 118 |              }
 | 118 |              }
 | 
												
													
														| 119 |              array_push($clearAction, $this->buildActionsRequest("removeTag", config("botApi.doneSurvey")));
 | 119 |              array_push($clearAction, $this->buildActionsRequest("removeTag", config("botApi.doneSurvey")));
 | 
												
													
														| 120 |              array_push($clearAction, $this->buildActionsRequest("setMenu", "default"));
 | 120 |              array_push($clearAction, $this->buildActionsRequest("setMenu", "default"));
 | 
												
													
														| 121 | -            
 |  | 
 | 
												
													
														|  | 
 | 121 | +
 | 
												
													
														| 122 |              $statusCode = $this->botActionsSend($lineUserId,$clearAction);
 | 122 |              $statusCode = $this->botActionsSend($lineUserId,$clearAction);
 | 
												
													
														| 123 |              if($statusCode == 200){
 | 123 |              if($statusCode == 200){
 | 
												
													
														| 124 |                  $survey_data->delete();
 | 124 |                  $survey_data->delete();
 | 
												
											
												
													
														|  | 
 |  | 
 | 
												
													
														| 157 |          }
 | 157 |          }
 | 
												
													
														| 158 |      }
 | 158 |      }
 | 
												
													
														| 159 |  
 | 159 |  
 | 
												
													
														| 160 | -    function botActionsSend($lineUserId,$actions){
 |  | 
 | 
												
													
														|  | 
 | 160 | +    function botActionsSend($lineUserId, $actions){
 | 
												
													
														|  | 
 | 161 | +
 | 
												
													
														|  | 
 | 162 | +        $tagType = [];
 | 
												
													
														|  | 
 | 163 | +        foreach ($actions as $k => $action) {
 | 
												
													
														|  | 
 | 164 | +            if (!isset($tagType[$action['type']])) {
 | 
												
													
														|  | 
 | 165 | +                $tagType[$action['type']] = [];
 | 
												
													
														|  | 
 | 166 | +            }
 | 
												
													
														|  | 
 | 167 | +            switch ($action['type']) {
 | 
												
													
														|  | 
 | 168 | +                case "addTag":
 | 
												
													
														|  | 
 | 169 | +                case "removeTag":
 | 
												
													
														|  | 
 | 170 | +                    foreach ($action['value'] as $value) {
 | 
												
													
														|  | 
 | 171 | +                        $tagType[$action['type']]['value'][] = $value;
 | 
												
													
														|  | 
 | 172 | +                    }
 | 
												
													
														|  | 
 | 173 | +                    unset($actions[$k]);
 | 
												
													
														|  | 
 | 174 | +                    break;
 | 
												
													
														|  | 
 | 175 | +            }
 | 
												
													
														|  | 
 | 176 | +        }
 | 
												
													
														|  | 
 | 177 | +
 | 
												
													
														|  | 
 | 178 | +        $actions = array_merge($actions, [[
 | 
												
													
														|  | 
 | 179 | +            'type' => 'addTag',
 | 
												
													
														|  | 
 | 180 | +            'value' => $tagType['addTag']['value']
 | 
												
													
														|  | 
 | 181 | +        ]]);
 | 
												
													
														|  | 
 | 182 | +
 | 
												
													
														|  | 
 | 183 | +        $actions = array_values($actions);
 | 
												
													
														|  | 
 | 184 | +
 | 
												
													
														| 161 |          $client = new Client();
 | 185 |          $client = new Client();
 | 
												
													
														| 162 |          $res_users = $client->request('POST', config('botApi.botActions'),[
 | 186 |          $res_users = $client->request('POST', config('botApi.botActions'),[
 | 
												
													
														| 163 |              'headers'=>$this->api_header,
 | 187 |              'headers'=>$this->api_header,
 |