// AddChatToHook adds the target chat to user's existing hook
483295
func (user *User) AddChatToHook(chatID int64) error {
	data, _ := user.getData()
	token := user.ServiceHookToken()

	for i, hook := range data.Hooks {
		if hook.Token == token {
			for _, service := range hook.Services {
				if service == user.ctx.ServiceName {
					for _, existingChatID := range hook.Chats {
						if existingChatID == chatID {
							return nil
						}
					}
					data.Hooks[i].Chats = append(data.Hooks[i].Chats, chatID)
					err := user.ctx.db.C("users").Update(bson.M{"_id": user.ID, "hooks.services": service}, bson.M{"$addToSet": bson.M{"hooks.$.chats": chatID}})

					return err
				}
			}
		}
	}
	err := errors.New("Can't add chat to serviceHook. Can't find a hook.")
	user.ctx.Log().Error(err)
	return err
}
117012
func SendChat(message string) {
    parameters := Chat{
        Content:          message,
        ExternalUserName: FlowdockRobotName,
    }

    sendChat(parameters)
}
1089738
func (c *Client) SetPreRequestHook(h func(*Client, *Request) error) *Client {
	if c.preReqHook != nil {
		c.Log.Printf("Overwriting an existing pre-request hook: %s", functionName(h))
	}
	c.preReqHook = h
	return c
}
873235
func (client *FakeTabletManagerClient) ExecuteHook(ctx context.Context, tablet *topodatapb.Tablet, hk *hook.Hook) (*hook.HookResult, error) {
	var hr hook.HookResult
	return &hr, nil
}
976276
func (c *ChatRPC) NewChatActivity(
	ctx context.Context, arg chat1.NewChatActivityArg) error {
	activityType, err := arg.Activity.ActivityType()
	if err != nil {
		return err
	}
	switch activityType {
	case chat1.ChatActivityType_NEW_CONVERSATION:
		// If we learn about a new conversation for a given TLF,
		// attempt to route it to the TLF.
		info := arg.Activity.NewConversation()
		err := c.newNotificationChannel(ctx, info.ConvID, info.Conv)
		if err != nil {
			return err
		}
	case chat1.ChatActivityType_INCOMING_MESSAGE:
		// If we learn about a new message for a given conversation ID,
		// let any registered callbacks for that conversation ID know.
		msg := arg.Activity.IncomingMessage()
		state, err := msg.Message.State()
		if err != nil {
			return err
		}
		if state != chat1.MessageUnboxedState_VALID {
			return nil
		}

		validMsg := msg.Message.Valid()
		msgType, err := validMsg.MessageBody.MessageType()
		if err != nil {
			return err
		}
		if msgType != chat1.MessageType_TEXT {
			return nil
		}
		body := validMsg.MessageBody.Text().Body

		c.convLock.RLock()
		cbs := c.convCBs[msg.ConvID.String()]
		c.convLock.RUnlock()

		// If this is on the self-write channel, cache it and we're
		// done.
		selfConvID, _ := c.getSelfConvInfoIfCached()
		if selfConvID.Eq(msg.ConvID) {
			return c.setLastWrittenConvID(ctx, body)
		}

		if len(cbs) == 0 {
			// No one is listening for this channel yet, so consider
			// it a new channel.
			err := c.newNotificationChannel(ctx, msg.ConvID, msg.Conv)
			if err != nil {
				return err
			}
		} else {
			for _, cb := range cbs {
				cb(msg.ConvID, body)
			}
		}

	}
	return nil
}
220528
func ParseCreateHook(raw []byte) (*CreatePayload, error) {
	hook := new(CreatePayload)
	if err := json.Unmarshal(raw, hook); err != nil {
		return nil, err
	}

	// it is possible the JSON was parsed, however,
	// was not from Gogs (maybe was from Bitbucket)
	// So we'll check to be sure certain key fields
	// were populated
	switch {
	case hook.Repo == nil:
		return nil, ErrInvalidReceiveHook
	case len(hook.Ref) == 0:
		return nil, ErrInvalidReceiveHook
	}
	return hook, nil
}
1244427
func (s *Session) Webhook(webhookID string) (st *Webhook, err error) {

	body, err := s.RequestWithBucketID("GET", EndpointWebhook(webhookID), nil, EndpointWebhooks)
	if err != nil {
		return
	}

	err = unmarshal(body, &st)

	return
}
1069372
func (chat *Chat) ServiceHookToken() string {
	data, _ := chat.getData()
	//TODO: test backward compatibility cases
	for _, hook := range data.Hooks {
		for _, service := range hook.Services {
			if service == chat.ctx.ServiceName {
				return hook.Token
			}
		}
	}
	token := "c" + rndStr.Get(10)
	chat.addHook(serviceHook{
		Token:    token,
		Services: []string{chat.ctx.ServiceName},
	})
	return token
}
178430
func (bto *BootstrapTokenOptions) AddTTLFlag(fs *pflag.FlagSet) {
	bto.AddTTLFlagWithName(fs, TokenTTL)
}
772267
func (s *FulfillmentActivity) SetCodeHook(v *CodeHook) *FulfillmentActivity {
	s.CodeHook = v
	return s
}
373062
func handleHook(a HookAction, err error) {
	if err != nil {
		// TODO: handle errors
	}

	switch a {
	case HookActionContinue:
		return
	case HookActionHalt:
		panic(HookActionHalt)
	}
}
145537
func Webhooks(client *messagebird.Client) *Paginator {
	return newPaginator(client, apiRoot+"/webhooks/", reflect.TypeOf(Webhook{}))
}
79930
func NewRollbarHook(token string, env string, levels []logrus.Level) logrus.Hook {
	if token == "" || env == "" {
		return nil
	}
	rollbar.Token = token
	rollbar.Environment = env
	rollbar.ErrorWriter = nil // default is stderr with fmt.Printf
	return &rollbarHook{levels: levels}
}
244373
func updateHookTrampoline(handle uintptr, op int, db *C.char, table *C.char, rowid int64) {
	callback := lookupHandle(handle).(func(int, string, string, int64))
	callback(op, C.GoString(db), C.GoString(table), rowid)
}
634984
func runHook(p *plugin.Plugin, event string) error {
	hook := p.Metadata.Hooks.Get(event)
	if hook == "" {
		return nil
	}

	prog := exec.Command("sh", "-c", hook)
	// TODO make this work on windows
	// I think its ... ¯\_(ツ)_/¯
	// prog := exec.Command("cmd", "/C", p.Metadata.Hooks.Install())

	debug("running %s hook: %s", event, prog)

	plugin.SetupPluginEnv(settings, p.Metadata.Name, p.Dir)
	prog.Stdout, prog.Stderr = os.Stdout, os.Stderr
	if err := prog.Run(); err != nil {
		if eerr, ok := err.(*exec.ExitError); ok {
			os.Stderr.Write(eerr.Stderr)
			return fmt.Errorf("plugin %s hook for %q exited with error", event, p.Metadata.Name)
		}
		return err
	}
	return nil
}
853875
func createHookTask(e Engine, t *HookTask) error {
	data, err := t.Payloader.JSONPayload()
	if err != nil {
		return err
	}
	t.UUID = gouuid.NewV4().String()
	t.PayloadContent = string(data)
	_, err = e.Insert(t)
	return err
}
531163
func NewHook(name string, params []string) *Hook {
	return &Hook{Name: name, Parameters: params}
}