messages

package
v0.2.4-r11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var DeleteCmd = &cobra.Command{
	Use:   "delete [[flags]]",
	Short: "Delete message",
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, _ []string) (err error) {
		ctx, client := helpers.MakeChatsServiceClientOrFail()

		var uuid string
		if uuid, err = cmd.Flags().GetString("uuid"); err != nil || uuid == "" {
			return errors.New("empty uuid")
		}
		resp, err := client.DeleteChatMessage(ctx, &proto.DeleteChatMessageRequest{
			Uuid: uuid,
		})

		if err != nil {
			fmt.Printf("Error while deleting message %s. Reason: %v.\n", uuid, err)
			return err
		}

		ok, err := tools.PrintJsonDataQ(cmd, resp)
		if err != nil {
			return err
		}
		if !ok {
			fmt.Printf("Successfuly deleted message %s.\n", uuid)
		}

		return err
	},
}

deleteCmd represents the delete command

View Source
var GetCmd = &cobra.Command{
	Use:   "get [[flags]]",
	Short: "get message",
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, _ []string) (err error) {
		ctx, client := helpers.MakeChatsServiceClientOrFail()

		var uuid string
		if uuid, err = cmd.Flags().GetString("uuid"); err != nil || uuid == "" {
			return errors.New("empty uuid")
		}
		message, err := client.GetChatMessage(ctx, &proto.GetChatMessageRequest{
			Uuid: uuid,
		})

		if err != nil {
			fmt.Printf("Error while fetching message %s. Reason: %v.\n", uuid, err)
			return err
		}

		ok, err := tools.PrintJsonDataQ(cmd, message)
		if err != nil {
			return err
		}
		if !ok {
			fmt.Printf("Successfuly fetched message %v\n", message)
		}

		return err
	},
}

GetCmd represents the get command

View Source
var ListCmd = &cobra.Command{
	Use:   "list [[flags]]",
	Short: "List messages from chat",
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, _ []string) (err error) {
		var uuid string
		if uuid, err = cmd.Flags().GetString("uuid"); err != nil || uuid == "" {
			return errors.New("empty chat uuid")
		}

		ctx, client := helpers.MakeChatsServiceClientOrFail()
		resp, err := client.ListChatMessages(ctx, &proto.ListChatMessagesRequest{
			ChatUuid: uuid,
		})

		if err != nil {
			fmt.Printf("Error while getting messages from chat %s. Reason: %v.\n", uuid, err)
			return err
		}

		ok, err := tools.PrintJsonDataQ(cmd, resp)
		if err != nil {
			return err
		}
		if !ok {
			fmt.Printf("Successfuly fetched messages %v.\n", resp.Messages)
		}

		return err
	},
}

ListCmd represents the list command

View Source
var SendCmd = &cobra.Command{
	Use:   "send [[flags]]",
	Short: "Send message",
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, _ []string) (err error) {
		ctx, client := helpers.MakeChatsServiceClientOrFail()

		var messageText string
		if messageText, err = cmd.Flags().GetString("message"); err != nil || messageText == "" {
			return errors.New("message text is empty")
		}
		var reciever string
		if reciever, err = cmd.Flags().GetString("to"); err != nil || reciever == "" {
			return errors.New("reciever is empty")
		}
		var entities []string
		if entities, err = cmd.Flags().GetStringSlice("entities"); err != nil {
			return err
		}

		msg, err := client.SendChatMessage(ctx, &proto.SendChatMessageRequest{
			Message: &proto.ChatMessage{
				To:      reciever,
				Message: messageText,
			},
			Entities: entities,
		})

		if err != nil {
			fmt.Printf("Error while sending message %s. Reason: %v.\n", messageText, err)
			return err
		}

		ok, err := tools.PrintJsonDataQ(cmd, msg)
		if err != nil {
			return err
		}
		if !ok {
			fmt.Printf("Successfuly sent message %v.\n", msg)
		}

		return err
	},
}

sendCmd represents the send message command

View Source
var UpdateCmd = &cobra.Command{
	Use:   "update [[flags]]",
	Short: "Update message",
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, _ []string) (err error) {
		var uuid string
		if uuid, err = cmd.Flags().GetString("uuid"); err != nil || uuid == "" {
			return errors.New("empty uuid")
		}
		var messageText string
		if messageText, err = cmd.Flags().GetString("message"); err != nil || messageText == "" {
			return errors.New("empty uuid")
		}

		ctx, client := helpers.MakeChatsServiceClientOrFail()
		if err != nil {
			fmt.Println("Error while parsing template")
			return err
		}

		resp, err := client.UpdateChatMessage(ctx, &proto.ChatMessage{
			Uuid:    uuid,
			Message: messageText,
		})

		if err != nil {
			fmt.Printf("Error while updating message. Reason: %v.\n", err)
			return err
		}

		ok, err := tools.PrintJsonDataQ(cmd, resp)
		if err != nil {
			return err
		}
		if !ok {
			fmt.Printf("Successfuly updated message %s.\n", uuid)
		}

		return err
	},
}

updateCmd represents the update command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL