// Send delivers media through bot b to recipient.
180746
func (v *Video) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
	params := map[string]string{
		"chat_id": to.Recipient(),
		"caption": v.Caption,
	}

	if v.Duration != 0 {
		params["duration"] = strconv.Itoa(v.Duration)
	}
	if v.Width != 0 {
		params["width"] = strconv.Itoa(v.Width)
	}
	if v.Height != 0 {
		params["height"] = strconv.Itoa(v.Height)
	}
	if v.SupportsStreaming {
		params["supports_streaming"] = "true"
	}

	embedSendOptions(params, opt)

	msg, err := b.sendObject(&v.File, "video", params, thumbnailToFilemap(v.Thumbnail))
	if err != nil {
		return nil, err
	}

	if vid := msg.Video; vid != nil {
		vid.File.stealRef(&v.File)
		*v = *vid
	} else if doc := msg.Document; doc != nil {
		// If video has no sound, Telegram can turn it into Document (GIF)
		doc.File.stealRef(&v.File)

		v.Caption = doc.Caption
		v.MIME = doc.MIME
		v.Thumbnail = doc.Thumbnail
	}

	return msg, nil
}
975512
func (b *Batch) Send(cb func()) {
	if b.Deflate {
		b.Writer.(*zlib.Writer).Flush()
	} else {
		b.Writer.(*bufio.Writer).Flush()
	}

	b.Message.PushPayload(b.Buf.Bytes())
	cb()
}
389611
func (c *conn) Send(m Message) error {
	b, err := m.MarshalBinary()
	if err != nil {
		return err
	}

	addr := &unix.SockaddrNetlink{
		Family: unix.AF_NETLINK,
	}

	return os.NewSyscallError("sendmsg", c.s.Sendmsg(b, nil, addr, 0))
}
271998
func (p *peer) Send(chID byte, msgBytes []byte) bool {
	if !p.IsRunning() {
		// see Switch#Broadcast, where we fetch the list of peers and loop over
		// them - while we're looping, one peer may be removed and stopped.
		return false
	} else if !p.hasChannel(chID) {
		return false
	}
	res := p.mconn.Send(chID, msgBytes)
	if res {
		p.metrics.PeerSendBytesTotal.With("peer_id", string(p.ID())).Add(float64(len(msgBytes)))
	}
	return res
}
109309
func (i *Invoice) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
	prices, _ := json.Marshal(i.Prices)

	params := map[string]string{
		"chat_id":         to.Recipient(),
		"title":           i.Title,
		"description":     i.Description,
		"start_parameter": i.Start,
		"payload":         i.Payload,
		"provider_token":  i.Token,
		"currency":        i.Currency,
		"prices":          string(prices),
	}
	embedSendOptions(params, opt)

	respJSON, err := b.Raw("sendInvoice", params)
	if err != nil {
		return nil, err
	}

	return extractMsgResponse(respJSON)
}
1258524
func (m *OutgoingMessage) Send() error {
	if m.ChatID == 0 {
		return errors.New("ChatID is empty")
	}

	if m.BotID == 0 {
		return errors.New("BotID is empty")
	}

	if m.Text == "" && m.FilePath == "" && m.Location == nil {
		return errors.New("Text, FilePath and Location are empty")
	}

	if m.ctx != nil && m.ctx.messageAnsweredAt == nil {
		n := time.Now()
		m.ctx.messageAnsweredAt = &n
	}

	return activeMessageSender.Send(m)
}
1360849
func (c *Conversation) Send(m ValidMessage, trace ...interface{}) ([]ValidMessage, error) {
	message := makeCopy(m)
	defer wipeBytes(message)

	if !c.Policies.isOTREnabled() {
		return []ValidMessage{makeCopy(message)}, nil
	}

	if c.debug && bytes.Index(message, []byte(debugString)) != -1 {
		c.dump(bufio.NewWriter(standardErrorOutput))
		return nil, nil
	}

	switch c.msgState {
	case plainText:
		return c.withInjections(c.sendMessageOnPlaintext(message, trace...))
	case encrypted:
		return c.withInjections(c.sendMessageOnEncrypted(message))
	case finished:
		c.messageEvent(MessageEventConnectionEnded)
		return c.withInjections(nil, newOtrError("cannot send message because secure conversation has finished"))
	}

	return c.withInjections(nil, newOtrError("cannot send message in current state"))
}
519712
func (e *Email) Send(addr string, a smtp.Auth) error {
	// Merge the To, Cc, and Bcc fields
	to := make([]string, 0, len(e.To)+len(e.Cc)+len(e.Bcc))
	to = append(append(append(to, e.To...), e.Cc...), e.Bcc...)
	for i := 0; i < len(to); i++ {
		addr, err := mail.ParseAddress(to[i])
		if err != nil {
			return err
		}
		to[i] = addr.Address
	}
	// Check to make sure there is at least one recipient and one "From" address
	if e.From == "" || len(to) == 0 {
		return errors.New("Must specify at least one From address and one To address")
	}
	sender, err := e.parseSender()
	if err != nil {
		return err
	}
	raw, err := e.Bytes()
	if err != nil {
		return err
	}
	return smtp.SendMail(addr, a, sender, to, raw)
}
912394
func (t *HTTPTransporter) Send(ctx context.Context, msg *Message) (sendError error) {
	return t.getState().Send(ctx, msg)
}
169882
func (m *Message) Send(smtpAddressPort string, auth smtp.Auth) error {

	to := m.Header.To()
	cc := m.Header.Cc()
	bcc := m.Header.Bcc()
	all := make([]string, 0, len(to)+len(cc)+len(bcc))

	all = append(append(append(all, to...), cc...), bcc...)
	for i := 0; i < len(all); i++ {
		address, err := mail.ParseAddress(all[i])
		if err != nil {
			return err
		}
		all[i] = address.Address
	}

	if len(all) == 0 {
		return errors.New("May not send email without a recipient (To, CC, or Bcc)")
	}

	from, err := mail.ParseAddress(m.Header.From())
	if err != nil {
		return err
	}

	if len(from.Address) == 0 {
		return errors.New("May not send email without a From address")
	}

	err = m.Save()
	if err != nil {
		return err
	}

	b, err := m.Bytes()
	if err != nil {
		return err
	}

	return smtp.SendMail(smtpAddressPort, auth, from.Address, all, b)
}
966185
func (r *response) Send(mt dhcp6.MessageType) (int, error) {
	p := &dhcp6.Packet{
		MessageType:   mt,
		TransactionID: r.req.TransactionID,
		Options:       r.options,
	}

	b, err := p.MarshalBinary()
	if err != nil {
		return 0, err
	}

	return r.conn.WriteTo(b, nil, r.remoteAddr)
}
778819
func (c *MConnection) Send(chID byte, msgBytes []byte) bool {
	if !c.IsRunning() {
		return false
	}

	c.Logger.Debug("Send", "channel", chID, "conn", c, "msgBytes", fmt.Sprintf("%X", msgBytes))

	// Send message to channel.
	channel, ok := c.channelsIdx[chID]
	if !ok {
		c.Logger.Error(fmt.Sprintf("Cannot send bytes, unknown channel %X", chID))
		return false
	}

	success := channel.sendBytes(msgBytes)
	if success {
		// Wake up sendRoutine if necessary
		select {
		case c.send <- struct{}{}:
		default:
		}
	} else {
		c.Logger.Debug("Send failed", "channel", chID, "conn", c, "msgBytes", fmt.Sprintf("%X", msgBytes))
	}
	return success
}
951892
func (c *Client) Send(req *Request, res Response) error {
	// TODO: handle retry, timeouts, etc.
	return c.send(req, res)
}
1100930
func (c *Client) Send(req *gomemcached.MCRequest) (rv *gomemcached.MCResponse, err error) {
	_, err = transmitRequest(c.conn, req)
	if err != nil {
		c.healthy = false
		return
	}
	resp, _, err := getResponse(c.conn, c.hdrBuf)
	c.healthy = !gomemcached.IsFatal(err)
	return resp, err
}
161779
func (bot TgBot) SendVideo(cid int, photo string, caption *string, duration *int, rmi *int, rm *ReplyMarkupInt) ResultWithMessage {
	var payload interface{} = SendVideoIDQuery{cid, photo, duration, caption, rmi, rm}
	if looksLikePath(photo) {
		payload = SendVideoPathQuery{cid, photo, duration, caption, rmi, rm}
	}
	return bot.SendVideoQuery(payload)
}
555957
func (s *SimpleSender) Send(data []byte) (int, error) {
	// no need for locking here, as the underlying fdNet
	// already serialized writes
	n, err := s.c.(*net.UDPConn).WriteToUDP(data, s.ra)
	if err != nil {
		return 0, err
	}
	if n == 0 {
		return n, errors.New("Wrote no bytes")
	}
	return n, nil
}
89484
func (c *Client) Send(b []byte) ([]byte, error) {
	c.Lock()
	defer c.Unlock()

	if err := c.w.Write(b); err != nil {
		return nil, err
	}
	return c.r.Read()
}