// NewMessage creates the message targeted to the current chat
349735
func (c *Context) NewMessage() *OutgoingMessage {
	bot := c.Bot()
	msg := &OutgoingMessage{}
	msg.BotID = bot.ID
	msg.FromID = bot.ID
	msg.WebPreview = true
	if c.Chat.ID != 0 {
		msg.ChatID = c.Chat.ID
	} else {
		msg.ChatID = c.User.ID
	}
	msg.ctx = c
	return msg
}
544991
func (s *DescribeEnvironmentStatusOutput) SetMessage(v string) *DescribeEnvironmentStatusOutput {
	s.Message = &v
	return s
}
539682
func NewMessageAction(label, text string) *MessageAction {
	return &MessageAction{
		Label: label,
		Text:  text,
	}
}
601232
func NewMessageItem(ch string, m *Message) Item {
	return Item{Type: TYPE_MESSAGE, Channel: ch, Message: m}
}
107773
func NewMessage(source MessageSource, data []byte, metadata Metadata, streamID MessageStreamID) *Message {
	msg := &Message{
		source:       source,
		streamID:     streamID,
		origStreamID: streamID,
		timestamp:    time.Now().UnixNano(),
	}

	msg.data.payload = getPayloadCopy(data)
	if metadata != nil && len(metadata) > 0 {
		msg.data.metadata = metadata
	}

	return msg
}
260680
func NewMessageWithTitle(message, title string) *Message {
	return &Message{Message: message, Title: title}
}
128469
func NewLineMessage(p level.Priority, args ...interface{}) Composer {
	m := NewLine(args...)
	_ = m.SetPriority(p)
	return m
}
121406
func NewChatMessage(message string, room int, player *player.Player) *ChatMessage {
	player.SetPlayerSummary()
	record := &ChatMessage{
		PlayerID: player.ID,

		Room:    room,
		Message: message,
	}

	return record
}
1051560
func (s *FailedCreateAssociation) SetMessage(v string) *FailedCreateAssociation {
	s.Message = &v
	return s
}
639863
func New(code int, msgs Messages, args ...interface{}) error {
	return newErrorBox(nil, code, msgs, args...)
}
105167
func NewMessage(topic string, payload interface{}, opts ...MessageOption) Message {
	return DefaultClient.NewMessage(topic, payload, opts...)
}
246854
func NewRunMessage(statement string, parameters map[string]interface{}) RunMessage {
	return RunMessage{
		statement:  statement,
		parameters: parameters,
	}
}
146899
func NewErrorMessage(errorCode, errorMessage string) []byte {
	return newErrorMessage([]byte(errorCode), []byte(errorMessage))
}
307903
func NewMessage(data []byte) (*Message, error) {
	message := &Message{}
	message.startByte = data[0]
	if len(data) <= 1 {
		return message, nil
	}
	message.Length = data[1]
	message.MessageType = data[2]
	message.Function = ZWaveFunction(data[3])

	var err error
	switch message.Function {
	case ApplicationCommandHandler:
		message.NodeID = data[5]

		message.Data, err = NewApplicationCommandHandler(data[7 : 7+data[6]])
	case DiscoveryNodes:

		message.Data, err = NewDiscoverdNodes(data[7 : 7+data[6]])
	case GetNodeProtocolInfo:

		message.Data, err = NewGetNodeProtocolInfo(data[4:])
	default:
		err = fmt.Errorf("Dropping message function='%s' with data %x (not implemented)", message.Function, data[4:])
	}

	if err != nil {
		return nil, err
	}

	logrus.Debugf("Message: %+v Message data: %+v", message, message.Data)
	return message, err

	// 1 FrameHeader (type of message)
	// 1 Message length
	// 1 Request (00) or Response (01)
	// 1 Function
	//
	// 1 (Node ID)
	// 1 (Command - length)
	// - (Command)
	// - (Transmit options)
	// - (Callback id)
	// 1 Checksum

	// Type
	//Request = 0x00,
	//Response = 0x01,
	//GetVersion = 0x15,
	//MemoryGetId = 0x20,
	//ClockSet = 0x30

	// Transmit options
	//Ack = 0x01,
	//LowPower = 0x02,
	//AutoRoute = 0x04,
	//ForceRoute = 0x08

}
1108848
func NewMessage(id uint64, phstr string) *Message {
	return &Message{id, Parts(phstr)}
}
1200325
func newMessageView(g *libkb.GlobalContext, conversationID chat1.ConversationID, m chat1.MessageUnboxed) (mv messageView, err error) {
	state, err := m.State()
	if err != nil {
		return mv, fmt.Errorf("unexpected empty message")
	}
	switch state {
	case chat1.MessageUnboxedState_ERROR:
		return newMessageViewError(g, conversationID, m.Error())
	case chat1.MessageUnboxedState_OUTBOX:
		return newMessageViewOutbox(g, conversationID, m.Outbox())
	case chat1.MessageUnboxedState_VALID:
		return newMessageViewValid(g, conversationID, m.Valid())
	default:
		return mv, fmt.Errorf("unexpected message state: %v", state)
	}

}
836427
func NewMessage(to []string, subject, body string) *Message {
	return NewMessageFrom(to, setting.MailService.From, subject, body)
}