(id string, responseWriter http.ResponseWriter, host string, lang string, signedIn bool, responseError func(string, ...interface{}))
| 138 | } |
| 139 | |
| 140 | func generateMessageAnswer(id string, responseWriter http.ResponseWriter, host string, lang string, signedIn bool, responseError func(string, ...interface{})) { |
| 141 | responseErrorStream := func(message *object.Message, errorText string) { |
| 142 | if err := writeMessageErrorStream(responseWriter, lang, message, errorText); err != nil { |
| 143 | if responseError != nil { |
| 144 | responseError(err.Error()) |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | emitStatus := func(statusText string) { |
| 150 | _ = writeStatusStream(responseWriter, statusText) |
| 151 | } |
| 152 | |
| 153 | message, err := object.GetMessage(id) |
| 154 | if err != nil { |
| 155 | responseErrorStream(message, err.Error()) |
| 156 | return |
| 157 | } |
| 158 | |
| 159 | if message == nil { |
| 160 | responseErrorStream(message, fmt.Sprintf("The message: %s is not found", id)) |
| 161 | return |
| 162 | } |
| 163 | |
| 164 | if message.Author != "AI" { |
| 165 | responseErrorStream(message, fmt.Sprintf("The message is invalid, message author should be \"AI\", but got \"%s\"", message.Author)) |
| 166 | return |
| 167 | } |
| 168 | if message.ReplyTo == "" { |
| 169 | responseErrorStream(message, "The message is invalid, message replyTo should not be empty") |
| 170 | return |
| 171 | } |
| 172 | if message.Text != "" { |
| 173 | responseErrorStream(message, fmt.Sprintf("The message is invalid, message text should be empty, but got \"%s\"", message.Text)) |
| 174 | return |
| 175 | } |
| 176 | |
| 177 | if strings.HasPrefix(message.ErrorText, "error, status code: 400, message: The response was filtered due to the prompt triggering") { |
| 178 | responseErrorStream(message, message.ErrorText) |
| 179 | return |
| 180 | } |
| 181 | |
| 182 | chatId := util.GetIdFromOwnerAndName(message.Owner, message.Chat) |
| 183 | chat, err := object.GetChat(chatId) |
| 184 | if err != nil { |
| 185 | responseErrorStream(message, err.Error()) |
| 186 | return |
| 187 | } |
| 188 | |
| 189 | //if chat == nil || chat.Organization != message.Organization { |
| 190 | // c.ResponseErrorStream(message, fmt.Sprintf("The chat: %s is not found", chatId)) |
| 191 | // return |
| 192 | //} |
| 193 | |
| 194 | store, err := object.ResolveStoreForChat(chat) |
| 195 | if err != nil { |
| 196 | responseErrorStream(message, err.Error()) |
| 197 | return |
no test coverage detected