//LastMessage returns the last message on the server
761312
func (s *Server) LastMessage() string {
	if len(s.Messages()) == 0 {
		return ""
	}

	return s.Messages()[len(s.Messages())-1]
}
859337
func (c *Context) DeleteMessage(om *OutgoingMessage) error {
	bot := c.Bot()
	if om.MsgID != 0 {
		log.WithField("msgID", om.MsgID).Debug("DeleteMessage")
	} else {
		om.ChatID = 0
		log.WithField("inlineMsgID", om.InlineMsgID).Debug("DeleteMessage")
	}

	var msg OutgoingMessage
	var ci *mgo.ChangeInfo
	var err error

	ci, err = c.db.C("messages").Find(bson.M{"_id": om.ID}).Apply(mgo.Change{Remove: true}, &msg)

	if err != nil {
		c.Log().WithError(err).Error("DeleteMessage messages remove error")
	}

	if msg.BotID == 0 {
		c.Log().Warn(fmt.Sprintf("DeleteMessage – message (_id=%s botid=%v id=%v) not found", om.ID, bot.ID, om.MsgID))
		return nil

	}
	if ci.Removed == 0 {
		c.Log().Warn(fmt.Sprintf("DeleteMessage – message (_id=%s botid=%v id=%v) not removed ", om.ID, bot.ID, om.MsgID))

		return nil
	}

	_, err = bot.API.Send(tg.DeleteMessageConfig{
		ChatID:    om.ChatID,
		MessageID: om.MsgID,
	})

	if err != nil {
		if err.(tg.Error).IsCantAccessChat() || err.(tg.Error).ChatMigrated() {
			if c.Callback != nil {
				c.AnswerCallbackQuery("Message can be outdated. Bot can't edit messages created before converting to the Super Group", false)
			}
		} else if err.(tg.Error).IsAntiFlood() {
			c.Log().WithError(err).Warn("TG Anti flood activated")
		}
		// Oops. error is occurred – revert the original message
		c.db.C("messages").Insert(om)
		return err
	}

	return nil
}
246882
func newMessage(verb messageVerb, sender *Node, senderHeartbeat uint32) message {
	return message{
		sender:          sender,
		senderHeartbeat: senderHeartbeat,
		verb:            verb,
	}
}
1254888
func (s *ChatService) MeMessage(channel string) *ChatMeMessageCall {
	var call ChatMeMessageCall
	call.service = s
	call.channel = channel
	return &call
}
1166374
func lastError(msg string) error {
	if err := checkError(msg); err != nil {
		return err
	}

	return errors.New(msg)
}
604448
func (httpsender *HTTPSender) OnMessage(m *utils.Message, done utils.Done) {
	var u string
	var headers map[string]string
	var code int
	var status string

	if httpsender.err != nil {
		httpsender.logger.Debugf("Could not send message: %v", httpsender.err)
		done(m, 100, httpsender.err.Error())
		return
	}

	data, err := m.PopPayload()
	defer func() {
		m.PushPayload(data)
		done(m, code, status)
	}()

	if err != nil {
		httpsender.logger.Debugf("Could not send message: %v", err)
		code = 101
		status = "Can't get payload of message: " + err.Error()
		return
	}

	if endpoint, exists := m.Opts.Get("http_endpoint"); exists {
		u = httpsender.URL + "/" + endpoint.(string)
	} else {
		u = httpsender.URL
	}

	buf := bytes.NewBuffer(data)
	req, _ := http.NewRequest("POST", u, buf)

	if h, exists := m.Opts.Get("http_headers"); exists {
		headers = h.(map[string]string)
		for k, v := range headers {
			req.Header.Add(k, v)
		}
	}

	res, err := httpsender.Client.Do(req)
	if err != nil {
		httpsender.logger.Warnf(err.Error())
		code = 1
		status = "HTTPSender error: " + err.Error()
		return
	}
	io.Copy(ioutil.Discard, res.Body)
	res.Body.Close()

	if res.StatusCode >= 400 {
		httpsender.logger.Warnf("Got status: %v", res.Status)
		code = 2
		status = "HTTPSender error: " + res.Status
		return
	}

	code = 0
	status = res.Status
	httpsender.logger.Debugf("Sent message: %v", string(buf.Bytes()))
}
355418
func (c *Client) Message(level string, msg string) {
	c.MessageWithExtras(level, msg, noExtras)
}
213975
func (s *RefreshSchemasStatus) SetLastFailureMessage(v string) *RefreshSchemasStatus {
	s.LastFailureMessage = &v
	return s
}
47750
func (c *Conn) WriteMessage(messageType int, data []byte) error {

	if c.isServer && (c.newCompressionWriter == nil || !c.enableWriteCompression) {
		// Fast path with no allocations and single frame.

		var mw messageWriter
		if err := c.beginMessage(&mw, messageType); err != nil {
			return err
		}
		n := copy(c.writeBuf[mw.pos:], data)
		mw.pos += n
		data = data[n:]
		return mw.flushFrame(true, data)
	}

	w, err := c.NextWriter(messageType)
	if err != nil {
		return err
	}
	if _, err = w.Write(data); err != nil {
		return err
	}
	return w.Close()
}
853909
func (api *Client) DeleteMessage(channel, messageTimestamp string) (string, string, error) {
	respChannel, respTimestamp, _, err := api.SendMessageContext(context.Background(), channel, MsgOptionDelete(messageTimestamp))
	return respChannel, respTimestamp, err
}
1194890
func (l *Limiter) OnMessage(m *utils.Message, done utils.Done) {
	if l.paused {
		<-l.keepSending
		l.currentMessages = 0
		l.currentBytes = 0
		l.paused = false
	}

	l.currentMessages++
	if l.Config.BytesLimit > 0 {
		if payload, err := m.PopPayload(); err == nil {
			l.currentBytes += uint64(len(payload))
			m.PushPayload(payload)
		}
	}
	done(m, 0, "")

	if l.Config.MessageLimit > 0 && l.currentMessages >= l.Config.MessageLimit ||
		l.Config.BytesLimit > 0 && l.currentBytes >= l.Config.BytesLimit {
		l.paused = true
	}
}
208766
func WriteMessage(msg proto.Message, w io.Writer) error {
	bz, err := proto.Marshal(msg)
	if err != nil {
		return err
	}
	return encodeByteSlice(w, bz)
}
190765
func (c *Channel) RequeueMessage(clientID int64, id MessageID, timeout time.Duration) error {
	// remove from inflight first
	msg, err := c.popInFlightMessage(clientID, id)
	if err != nil {
		return err
	}
	c.removeFromInFlightPQ(msg)
	atomic.AddUint64(&c.requeueCount, 1)

	if timeout == 0 {
		c.exitMutex.RLock()
		if c.Exiting() {
			c.exitMutex.RUnlock()
			return errors.New("exiting")
		}
		err := c.put(msg)
		c.exitMutex.RUnlock()
		return err
	}

	// deferred requeue
	return c.StartDeferredTimeout(msg, timeout)
}
89851
func (s *Session) ChannelMessageAck(channelID, messageID, lastToken string) (st *Ack, err error) {

	body, err := s.RequestWithBucketID("POST", EndpointChannelMessageAck(channelID, messageID), &Ack{Token: lastToken}, EndpointChannelMessageAck(channelID, ""))
	if err != nil {
		return
	}

	err = unmarshal(body, &st)
	return
}
1030632
func (c *Channel) SendMessage(message *Message) {
	c.lastEventID = message.id

	for c, open := range c.clients {
		if open {
			c.send <- message
		}
	}
}
585599
func NewSentMessage(params *MessageParams) (*sentMessage, error) {
	const payloadSizeFieldMaxSize = 4
	msg := sentMessage{}
	msg.Raw = make([]byte, 1,
		flagsLength+payloadSizeFieldMaxSize+len(params.Payload)+len(params.Padding)+signatureLength+padSizeLimit)
	msg.Raw[0] = 0 // set all the flags to zero
	msg.addPayloadSizeField(params.Payload)
	msg.Raw = append(msg.Raw, params.Payload...)
	err := msg.appendPadding(params)
	return &msg, err
}
1022088
func (s *AssociationStatus) SetMessage(v string) *AssociationStatus {
	s.Message = &v
	return s
}