func process_message_pkg(buff *s.OutPkg, in *s.InPkg, context *BotContext) (*s.OutPkg, bool, error) { var err error var isDeferred bool if in.Message.Type == "error" { log.Printf("error because type of message is error:\n %+v", in.Message.Error) return buff, false, errors.New(fmt.Sprintf("Error because type of message id: %+v is error", in.Message.ID)) } in_commands := in.Message.Commands for _, command := range *in_commands { action := command.Action if commandProcessor, ok := context.MessageProcessors[action]; ok { log.Printf("BOT found [%v] action", action) buff, isDeferred, err = process_message(commandProcessor, buff, in) } else { err = errors.New("Команда не поддерживается.") buff.Message = &s.OutMessage{ Thread: in.Message.Thread, ID: u.GenStringId(), Type: "chat", Body: err.Error(), } } } return buff, isDeferred, err }
func process_car_state(taxiContext *TaxiContext, botContext *m.BotContext, api_order Order, db_order *d.OrderWrapper) { var result s.OutPkg result.To = db_order.Whom car_info := taxiContext.Cars.GetCarInfo(api_order.IDCar) if car_info == nil { log.Printf("ALERT! CAR CHANGED TO NOT RECOGNIZED ID") return } result.Message = &s.OutMessage{Body: fmt.Sprintf("Ваша машина изменилась на %v", car_info)} taxiContext.Notifier.Notify(result) }
func process_message(commandProcessor s.MessageCommandProcessor, buff *s.OutPkg, in *s.InPkg) (*s.OutPkg, bool, error) { messageResult := commandProcessor.ProcessMessage(in) buff.Message = &s.OutMessage{ Thread: in.Message.Thread, ID: u.GenStringId(), Type: "chat", } if messageResult.Type != "" { buff.Message.Type = messageResult.Type } buff.Message.Body = messageResult.Body buff.Message.Commands = messageResult.Commands log.Printf("message result\ntype: %+v \nbody:%+v\ncommands:%+v\ndeffered?: %+v", messageResult.Type, buff.Message.Body, buff.Message.Commands, messageResult.IsDeferred) return buff, messageResult.IsDeferred, messageResult.Error }