// DispatchMessage posts the message to messenger, return the error if there's any
559410
func (r *Response) DispatchMessage(m interface{}) error {
	data, err := json.Marshal(m)
	if err != nil {
		return err
	}

	req, err := http.NewRequest("POST", SendMessageURL, bytes.NewBuffer(data))
	if err != nil {
		return err
	}

	req.Header.Set("Content-Type", "application/json")
	req.URL.RawQuery = "access_token=" + r.token

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode == 200 {
		return nil
	}
	return checkFacebookError(resp.Body)
}
235580
func (client *Client) PushMessage(to string, messages ...SendingMessage) *PushMessageCall {
	return &PushMessageCall{
		c:        client,
		to:       to,
		messages: messages,
	}
}
1145951
func NewMessage(data interface{}) (*Message, error) {
	m := &Message{}
	if err := m.unmarshalInterface(data); err != nil {
		return nil, err
	}
	return m, nil
}
224006
func (dht *IpfsDHT) sendMessage(ctx context.Context, p peer.ID, pmes *pb.Message) error {
	ctx, _ = tag.New(ctx, metrics.UpsertMessageType(pmes))

	ms, err := dht.messageSenderForPeer(ctx, p)
	if err != nil {
		stats.Record(ctx, metrics.SentMessageErrors.M(1))
		return err
	}

	if err := ms.SendMessage(ctx, pmes); err != nil {
		stats.Record(ctx, metrics.SentMessageErrors.M(1))
		return err
	}

	stats.Record(
		ctx,
		metrics.SentMessages.M(1),
		metrics.SentBytes.M(int64(pmes.Size())),
	)
	logger.Event(ctx, "dhtSentMessage", dht.self, p, pmes)
	return nil
}
156465
func (c *Client) dispatchPMessage(message redis.PMessage) {
	if listeners, exists := c.subscribed[message.Pattern]; exists {
		for _, l := range listeners {
			l.PMessages <- message
		}
	}
}
463289
func (c *Client) PublishMessage(msg *packet.Message) (GenericFuture, error) {
	c.mutex.Lock()
	defer c.mutex.Unlock()

	// check if connected
	if atomic.LoadUint32(&c.state) != clientConnected {
		return nil, ErrClientNotConnected
	}

	// allocate publish packet
	publish := packet.NewPublish()
	publish.Message = *msg

	// set packet id
	if msg.QOS > 0 {
		publish.ID = c.Session.NextID()
	}

	// create future
	publishFuture := future.New()

	// store future
	c.futureStore.Put(publish.ID, publishFuture)

	// store packet if at least qos 1
	if msg.QOS > 0 {
		err := c.Session.SavePacket(session.Outgoing, publish)
		if err != nil {
			return nil, c.cleanup(err, true, false)
		}
	}

	// send packet
	err := c.send(publish, true)
	if err != nil {
		return nil, c.cleanup(err, false, false)
	}

	// complete and remove qos 0 future
	if msg.QOS == 0 {
		publishFuture.Complete()
		c.futureStore.Delete(publish.ID)
	}

	return publishFuture, nil
}
202555
func (soc *Socket) SendMessage(parts ...interface{}) (total int, err error) {
	return soc.sendMessage(0, parts...)
}
106886
func (c *ChromeTarget) dispatchResponse(msg []byte) {
	f := &responseHeader{}
	err := json.Unmarshal(msg, f)
	if err != nil {
		c.debugf("error reading response data from chrome target: %v\n", err)
	}

	c.replyLock.Lock()

	if r, ok := c.replyDispatcher[f.Id]; ok {
		delete(c.replyDispatcher, f.Id)
		c.replyLock.Unlock()
		c.debugf("%d dispatching\n", f.Id)
		c.dispatchWithTimeout(r, f.Id, msg)
		return
	}
	c.replyLock.Unlock()

	c.checkTargetDisconnected(f.Method)

	c.eventLock.RLock()
	if r, ok := c.eventDispatcher[f.Method]; ok {
		c.eventLock.RUnlock()
		c.debugf("dispatching %s event: %s\n", f.Method, string(msg))
		go r(c, msg)
		return

	}
	c.eventLock.RUnlock()

	if c.debugEvents == true {
		log.Printf("\n\nno event recv bound for: %s\n", f.Method)
		log.Printf("data: %s\n\n", string(msg))
	}
}
538537
func (client *Client) ReplyMessage(replyToken string, messages ...SendingMessage) *ReplyMessageCall {
	return &ReplyMessageCall{
		c:          client,
		replyToken: replyToken,
		messages:   messages,
	}
}
617847
func (p *PushEventCommit) GetMessage() string {
	if p == nil || p.Message == nil {
		return ""
	}
	return *p.Message
}
228586
func (l *Linearizer) dispatchEvent(e *event) {
	defer l.md.Unlock()
	l.me.Lock()
	defer l.me.Unlock()
	if e.n+l.eventsSize > l.bufferSize {
		return
	}
	l.events = append(l.events, e)
	l.eventsSize += e.n
}
1158851
func WriteMessage(w io.Writer, m *Message) error {
	_, err := w.Write(m.raw)
	return err
}
668337
func CheckMessage(req PushNotification) error {
	var msg string

	// ignore send topic mesaage from FCM
	if !req.IsTopic() && len(req.Tokens) == 0 && len(req.To) == 0 {
		msg = "the message must specify at least one registration ID"
		LogAccess.Debug(msg)
		return errors.New(msg)
	}

	if len(req.Tokens) == PlatFormIos && len(req.Tokens[0]) == 0 {
		msg = "the token must not be empty"
		LogAccess.Debug(msg)
		return errors.New(msg)
	}

	if req.Platform == PlatFormAndroid && len(req.Tokens) > 1000 {
		msg = "the message may specify at most 1000 registration IDs"
		LogAccess.Debug(msg)
		return errors.New(msg)
	}

	// ref: https://firebase.google.com/docs/cloud-messaging/http-server-ref
	if req.Platform == PlatFormAndroid && req.TimeToLive != nil && (*req.TimeToLive < uint(0) || uint(2419200) < *req.TimeToLive) {
		msg = "the message's TimeToLive field must be an integer " +
			"between 0 and 2419200 (4 weeks)"
		LogAccess.Debug(msg)
		return errors.New(msg)
	}

	return nil
}
109937
func (s *BatchResultErrorEntry) SetMessage(v string) *BatchResultErrorEntry {
	s.Message = &v
	return s
}
175314
func (p *Peer) QueueMessage(msg wire.Message, doneChan chan<- struct{}) {
	p.QueueMessageWithEncoding(msg, doneChan, wire.BaseEncoding)
}
1168053
func (fw *Framework) NewMessage(payload string, agent string, collective string, msgType string, request *Message) (msg *Message, err error) {
	msg, err = NewMessage(payload, agent, collective, msgType, request, fw)

	return
}
1068139
func (v *TApplicationException) GetMessage() (o string) {
	if v != nil && v.Message != nil {
		return *v.Message
	}

	return
}