// Action triggers the action passed to it.
513155
func (mod *SerialBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}
	text := ""

	switch action.Name {
	case "send":
		action.Options.Bind("text", &text)

		bufOut := new(bytes.Buffer)
		err := binary.Write(bufOut, binary.LittleEndian, []byte(text))
		if err != nil {
			panic(err)
		}

		_, err = mod.conn.Write(bufOut.Bytes())
		if err != nil {
			panic(err)
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
545273
func (a *ActionAPI) Actions(arg params.Entities) (params.ActionResults, error) {
	if err := a.checkCanRead(); err != nil {
		return params.ActionResults{}, errors.Trace(err)
	}

	response := params.ActionResults{Results: make([]params.ActionResult, len(arg.Entities))}
	for i, entity := range arg.Entities {
		currentResult := &response.Results[i]
		tag, err := names.ParseTag(entity.Tag)
		if err != nil {
			currentResult.Error = common.ServerError(common.ErrBadId)
			continue
		}
		actionTag, ok := tag.(names.ActionTag)
		if !ok {
			currentResult.Error = common.ServerError(common.ErrBadId)
			continue
		}
		m, err := a.state.Model()
		if err != nil {
			return params.ActionResults{}, errors.Trace(err)
		}
		action, err := m.ActionByTag(actionTag)
		if err != nil {
			currentResult.Error = common.ServerError(common.ErrBadId)
			continue
		}
		receiverTag, err := names.ActionReceiverTag(action.Receiver())
		if err != nil {
			currentResult.Error = common.ServerError(err)
			continue
		}
		response.Results[i] = common.MakeActionResult(receiverTag, action)
	}
	return response, nil
}
1053329
func (sw *SleepWorkflow) Action(ctx context.Context, path, name string) error {
	sw.mu.Lock()
	defer sw.mu.Unlock()

	// Change our state.
	log.Infof("SleepWorkflow.Action(%v) called.", name)
	paused := sw.data.Paused
	switch name {
	case pauseAction:
		sw.data.Paused = true
		sw.logger.Infof("Paused")
	case resumeAction:
		sw.data.Paused = false
		sw.logger.Infof("Resumed")
	default:
		sw.logger.Errorf("Unknown action %v called", name)
		return fmt.Errorf("unknown action %v", name)
	}
	if paused == sw.data.Paused {
		// Nothing changed.
		return nil
	}

	// UI update and Checkpoint.
	sw.uiUpdateLocked()
	sw.node.BroadcastChanges(false /* updateChildren */)
	return sw.checkpointLocked(ctx)
}
93423
func (mod *OpenweathermapBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "get_current_weather":
		var location string
		action.Options.Bind("location", &location)

		err := mod.current.CurrentByName(location)
		if err != nil {
			mod.LogErrorf("Failed to fetch weather: %v", err)
			return nil
		}

		mod.TriggerCurrentWeatherEvent()

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
401424
func (kf *UITestFixer) Action(ctx context.Context, name string) error {
	if name == "Success" {
		return nil
	}
	if name == "Error" {
		return fmt.Errorf("oh no, you pressed the Error button")
	}
	return fmt.Errorf("unknown UITestFixer action: %v", name)
}
968260
func (mod *SimplepushBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "send":
		sm := simplepush.Message{
			SimplePushKey: mod.key,
			Encrypt:       mod.password != "",
			Password:      mod.password,
			Salt:          mod.salt,
		}
		action.Options.Bind("title", &sm.Title)
		action.Options.Bind("message", &sm.Message)
		action.Options.Bind("event", &sm.Event)

		simplepush.Send(sm)

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
215625
func (factory *SpaceAPIBeeFactory) Actions() []bees.ActionDescriptor {
	actions := []bees.ActionDescriptor{
		{
			Namespace:   factory.Name(),
			Name:        "status",
			Description: "Gets the Status of a LabAPI instance",
			Options:     []bees.PlaceholderDescriptor{},
		},
	}
	return actions
}
43844
func (m *Model) Action(id string) (Action, error) {
	actionLogger.Tracef("Action() %q", id)
	st := m.st
	actions, closer := st.db().GetCollection(actionsC)
	defer closer()

	doc := actionDoc{}
	err := actions.FindId(id).One(&doc)
	if err == mgo.ErrNotFound {
		return nil, errors.NotFoundf("action %q", id)
	}
	if err != nil {
		return nil, errors.Annotatef(err, "cannot get action %q", id)
	}
	actionLogger.Tracef("Action() %q found %+v", id, doc)
	return newAction(st, doc), nil
}
1264283
func (mod *TwilioBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "send":
		body := ""
		action.Options.Bind("body", &body)

		_, err := twilio.NewMessage(mod.client, mod.fromNumber, mod.toNumber, twilio.Body(body))
		if err != nil {
			mod.LogErrorf("Error sending twilio SMS: %s", err)
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
781112
func (mod *PushoverBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "send":
		var message, title, nurl, urlTitle string
		action.Options.Bind("message", &message)
		action.Options.Bind("title", &title)
		action.Options.Bind("url", &nurl)
		action.Options.Bind("url_title", &urlTitle)

		msg := url.Values{}
		msg.Set("token", mod.token)
		msg.Set("user", mod.userToken)
		msg.Set("message", message)

		if nurl != "" {
			msg.Set("url", nurl)
		}
		if urlTitle != "" {
			msg.Set("url_title", urlTitle)
		}
		if title != "" {
			msg.Set("title", title)
		}

		mod.Logln(msg)
		resp, err := http.PostForm("https://api.pushover.net/1/messages.json", msg)
		if err != nil {
			panic(err)
		}
		defer resp.Body.Close()
		if resp.StatusCode == 200 {
			mod.Logln("Pushover send message success.")
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
1364680
func (mod *AlertOverBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "send":
		var receiver, title, content, weburl, priority string
		action.Options.Bind("receiver", &receiver)
		action.Options.Bind("title", &title)
		action.Options.Bind("content", &content)
		action.Options.Bind("url", &weburl)
		action.Options.Bind("priority", &priority)

		if priority == "" {
			priority = "0"
		}

		// the message must be plain text, so
		// remove the HTML tags, such as <html></html> and so on
		re, _ := regexp.Compile("\\<[\\S\\s]+?\\>")
		content = re.ReplaceAllString(content, "\n")

		data := url.Values{
			"source":   {mod.source},
			"receiver": {receiver},
			"title":    {title},
			"content":  {content},
			"url":      {weburl},
			"priority": {priority},
		}
		resp, err := http.PostForm("https://api.alertover.com/v1/alert", data)
		if err != nil {
			panic(err)
		}
		defer resp.Body.Close()
		if resp.StatusCode == 200 {
			mod.Logln("AlertOver send message success.")
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
693825
func (p *ParallelRunner) Action(ctx context.Context, path, name string) error {
	switch name {
	case actionNameRetry:
		// Extract the path relative to the root node.
		parts := strings.Split(path, "/")
		taskID := strings.Join(parts[2:], "/")
		return p.triggerRetry(taskID)
	case actionNameApproveFirstTask:
		p.mu.Lock()
		defer p.mu.Unlock()

		if p.firstTaskApproved != nil {
			close(p.firstTaskApproved)
			p.firstTaskApproved = nil
			return nil
		}
		return fmt.Errorf("ignored the approval action %v because no pending approval found: it might be already approved before", actionNameApproveFirstTask)
	case actionNameApproveRemainingTasks:
		p.mu.Lock()
		defer p.mu.Unlock()

		if p.remainingTasksApproved != nil {
			close(p.remainingTasksApproved)
			p.remainingTasksApproved = nil
			return nil
		}
		return fmt.Errorf("ignored the approval action %v because no pending approval found: it might be already approved before", actionNameApproveRemainingTasks)
	default:
		return fmt.Errorf("unknown action: %v", name)
	}
}
713009
func (mod *CleverbotBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "send_message":
		var text string
		action.Options.Bind("text", &text)

		resp, err := mod.client.Ask(text)
		if err != nil {
			mod.LogErrorf("Failed to ask cleverbot: %v", err)
			return nil
		}

		ev := bees.Event{
			Bee:  mod.Name(),
			Name: "answer",
			Options: []bees.Placeholder{
				{
					Name:  "answer",
					Type:  "string",
					Value: resp,
				},
			},
		}
		mod.evchan <- ev

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
668924
func (r *ResourceDefinition) CanonicalAction() *ActionDefinition {
	name := r.CanonicalActionName
	if name == "" {
		name = "show"
	}
	ca, _ := r.Actions[name]
	return ca
}
124278
func (s *AddLayerVersionPermissionInput) SetAction(v string) *AddLayerVersionPermissionInput {
	s.Action = &v
	return s
}
881819
func (c *HookContext) ActionData() (*ActionData, error) {
	if c.actionData == nil {
		return nil, errors.New("not running an action")
	}
	return c.actionData, nil
}
395933
func (mod *DevrantBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "surprise":
		rant, err := mod.client.Surprise()
		if err != nil {
			mod.LogErrorf("Failed to fetch surprise rant: %v", err)
		}

		mod.triggerEvent(rant)

	case "weekly":
		rants, err := mod.client.WeeklyRants()
		if err != nil {
			mod.LogErrorf("Failed to fetch weekly rants: %v", err)
		}

		for _, v := range rants {
			mod.triggerEvent(v)
		}

	case "rant":
		limit := 0
		action.Options.Bind("limit", &limit)

		rants, err := mod.client.Rants("", limit, 0)
		if err != nil {
			mod.LogErrorf("Failed to fetch rants: %v", err)
		}

		for i := range rants {
			mod.triggerEvent(rants[i])
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}