func FormShopCommands(db *d.MainDb, config *c.ShopConfig) *m.BotContext {
	var ShopRequestCommands = map[string]s.RequestCommandProcessor{
		"commands": ShopCommandsProcessor{MainDb: *db},
	}

	var ShopMessageCommands = map[string]s.MessageCommandProcessor{
		"information":     ShopInformationProcessor{Info: config.Info},
		"authorise":       ShopLogInMessageProcessor{MainDb: *db},
		"log_out":         ShopLogOutMessageProcessor{MainDb: *db},
		"orders_state":    ShopOrderStateProcessor{MainDb: *db},
		"support_message": ShopSupportMessageProcessor{},
		"balance":         ShopBalanceProcessor{},
	}

	context := m.BotContext{}
	context.MessageProcessors = ShopMessageCommands
	context.RequestProcessors = ShopRequestCommands
	context.Check = func() (string, bool) {
		if !db.Check() {
			return "Ошибка в подключении к БД попробуйте позже", false
		}
		return "All ok!", true

	}
	return &context
}
Example #2
0
func FormBotCoffeeContext(config c.CoffeeConfig, store *db.MainDb, coffeeHouseConfiguration *CoffeeHouseConfiguration, configStore *db.ConfigurationStorage) *m.BotContext {
	commandsGenerator := func(in *s.InPkg) (*[]s.OutCommand, error) {
		lastOrder, err := store.Orders.GetByOwnerLast(in.From, config.Chat.CompanyId)
		if err != nil {
			log.Printf("COFFEE BOT error getting last order for %v is: %v", in.From, err)
			return nil, err
		}
		var isFirst, isActive bool
		if lastOrder != nil {
			isFirst = false
			isActive = lastOrder.Active
		}
		commands := getCommands(coffeeHouseConfiguration, isFirst, isActive)
		return commands, nil
	}

	result := m.BotContext{}
	result.RequestProcessors = map[string]s.RequestCommandProcessor{
		"commands": &RequestCommandsProcessor{CommandsFunc: commandsGenerator},
	}
	result.MessageProcessors = map[string]s.MessageCommandProcessor{
		"":            m.NewFuncTextBodyProcessor(store, commandsGenerator, config.Chat.CompanyId, nil),
		"information": m.NewUpdatableInformationProcessor(configStore, commandsGenerator, config.Chat.CompanyId),
		"order_bake":  &OrderBakeProcessor{Storage: store, CompanyName: config.Chat.CompanyId, CommandsFunc: commandsGenerator},
		"order_drink": &OrderDrinkProcessor{Storage: store, CompanyName: config.Chat.CompanyId, CommandsFunc: commandsGenerator},
		"cancel":      &CancelOrderProcessor{Storage: store, CompanyName: config.Chat.CompanyId, CommandsFunc: commandsGenerator},
		"repeat":      &RepeatOrderProcessor{Storage: store, CompanyName: config.Chat.CompanyId, CommandsFunc: commandsGenerator},
	}
	return &result
}
func FormRPBotContext(conf c.Configuration) *m.BotContext {
	result := m.BotContext{}
	result.RequestProcessors = map[string]s.RequestCommandProcessor{
		"commands": RuPostCommandsProcessor{},
	}
	result.MessageProcessors = map[string]s.MessageCommandProcessor{
		"tracking": RuPostTrackingProcessor{Url: conf.RuPost.ExternalUrl},
	}
	return &result
}
Example #4
0
func FormVoteBotContext(conf c.Configuration, db_handler *d.MainDb) *m.BotContext {
	context := m.BotContext{}
	vh, _ := NewVotingHandler(conf.Main.Database.ConnString, conf.Main.Database.Name)
	context.Check = func() (string, bool) {
		if vh.Check() {
			return "", true
		}
		return "", false
	}
	context.RequestProcessors = map[string]s.RequestCommandProcessor{
		"commands": &VoteCommandProcessor{DictUrl: conf.Vote.DictUrl, Storage: vh},
	}
	context.MessageProcessors = map[string]s.MessageCommandProcessor{
		"add_company":  &VoteConsiderCompanyProcessor{Storage: vh, DictUrl: conf.Vote.DictUrl, Answers: conf.Vote.Answers, MainStorage: db_handler},
		"show_results": &VoteResultsProcessor{Storage: vh, DictUrl: conf.Vote.DictUrl},
		"information":  &VoteInformationProcessor{Storage: vh, DictUrl: conf.Vote.DictUrl},
	}
	return &context
}
Example #5
0
func FormChatBotContext(store *db.MainDb, confStore *db.ConfigurationStorage, companyId string) *msngr.BotContext {
	result := msngr.BotContext{}
	result.RequestProcessors = map[string]s.RequestCommandProcessor{
		"commands": &ChatRequestProcessor{
			Commands: &[]s.OutCommand{
				s.OutCommand{
					Title:    "Информация",
					Action:   "information",
					Position: 0,
				},
			},
		},
	}
	chatStorage := NewChatStorage(store)

	result.MessageProcessors = map[string]s.MessageCommandProcessor{
		"information": &ChatInformationProcessor{CompanyId: companyId, ConfigStorage: confStore},
		"":            &ChatMessageProcessor{Storage: chatStorage, CompanyId: companyId, MessageStorage: store.Messages, ConfigStorage: confStore},
	}

	return &result
}
Example #6
0
func FormQuestBotContext(conf c.Configuration, qConf c.QuestConfig, qs *QuestStorage, db *db.MainDb, cs *db.ConfigurationStorage) *m.BotContext {
	result := m.BotContext{}
	commandsGenerator := func(in *s.InPkg) (*[]s.OutCommand, error) {
		commands := getCommands(qConf.QuestTimes)
		return commands, nil
	}

	result.RequestProcessors = map[string]s.RequestCommandProcessor{
		"commands":&QuestCommandRequestProcessor{Storage:qs, Config:qConf},
	}

	result.MessageProcessors = map[string]s.MessageCommandProcessor{
		"information":m.NewUpdatableInformationProcessor(cs, commandsGenerator, qConf.Chat.CompanyId),
		"enroll": &QuestEnrollProcessor{Store:qs, Config:qConf},
		"":QuestMessageProcessor{Storage:qs, Config:qConf},
	}

	notifier := n.NewNotifier(conf.Main.CallbackAddr, qConf.Chat.Key, db)
	additionalNotifier := n.NewNotifier(conf.Main.CallbackAddr, qConf.AdditionalKey, db)
	go Run(qConf, qs, notifier, additionalNotifier)

	return &result
}
func FormTaxiBotContext(im *ExternalApiMixin, db_handler *d.MainDb, cfgStore *d.ConfigurationStorage, tc c.TaxiConfig, ah AddressHandler, cc *CarsCache) *m.BotContext {
	context := m.BotContext{}
	context.Check = func() (detail string, ok bool) {
		ok = im.API.IsConnected()
		if !ok {
			detail = "Ошибка в подключении к сервису такси. Попробуйте позже."
		} else {
			return "", db_handler.Check()
		}
		return detail, ok
	}
	context.Commands = EnsureAvailableCommands(GetCommands(tc.DictUrl), tc.AvailableCommands)

	context.Name = tc.Name
	context.RequestProcessors = map[string]s.RequestCommandProcessor{
		"commands": &TaxiCommandsProcessor{MainDb: *db_handler, context: &context},
	}

	commandsGenerator := func(in *s.InPkg) (*[]s.OutCommand, error) {
		command, err := form_commands(in.From, *db_handler, &context)
		return command, err
	}

	context.MessageProcessors = map[string]s.MessageCommandProcessor{
		"information":      m.NewUpdatableInformationProcessor(cfgStore, commandsGenerator, tc.Chat.CompanyId),
		"new_order":        &TaxiNewOrderProcessor{ExternalApiMixin: *im, MainDb: *db_handler, context: &context, AddressHandler: ah, Config: tc},
		"cancel_order":     &TaxiCancelOrderProcessor{ExternalApiMixin: *im, MainDb: *db_handler, context: &context, alert_phone: tc.Information.Phone},
		"calculate_price":  &TaxiCalculatePriceProcessor{ExternalApiMixin: *im, context: &context, AddressHandler: ah, Config: tc},
		"feedback":         &TaxiFeedbackProcessor{ExternalApiMixin: *im, MainDb: *db_handler, context: &context},
		"write_dispatcher": &TaxiWriteDispatcherMessageProcessor{ExternalApiMixin: *im, MainDb: *db_handler},
		"callback_request": &TaxiCallbackRequestMessageProcessor{ExternalApiMixin: *im},
		"where_it":         &TaxiWhereItMessageProcessor{ExternalApiMixin: *im, MainDb: *db_handler, context: &context},
		"car_position":     &TaxiCarPositionMessageProcessor{ExternalApiMixin: *im, MainDb: *db_handler, context: &context, Cars: NewCarInfoProvider(cc)},
		"":                 &TaxiWriteDispatcherMessageProcessor{ExternalApiMixin: *im, MainDb: *db_handler},
	}
	context.Settings = make(map[string]interface{})
	context.Settings["not_send_price"] = tc.Api.NotSendPrice
	if tc.Markups != nil {
		context.Settings["markups"] = *tc.Markups
	}
	if tc.Api.Data.RefreshOrdersTimeStep != 0 {
		context.Settings["refresh_orders_time_step"] = time.Duration(tc.Api.Data.RefreshOrdersTimeStep) * time.Second
	} else {
		context.Settings["refresh_orders_time_step"] = 10 * time.Second
	}

	return &context
}