GithubHelp home page GithubHelp logo

icq's Introduction

Проект архивирован потому что появилась официальная библиотека https://github.com/mail-ru-im/bot-golang

ICQ Bot Api Go

Sourcegraph GoDoc Go Report Card License

Основана на новом Bot Api (https://icq.com/botapi/)

Реализованы все методы и соответствуют документации.

Методы

api.Events.Get(ctx context.Context) <-chan EventInterface
api.Self.Get() (*Bot, error)
api.Messages.SendText(chatID string, text string, replyMsgID []string, forwardChatID string, forwardMsgID string) (*Msg, error)
api.Messages.SendExistsFile(chatID string, fileID string, caption string, replyMsgID []string, forwardChatID string, forwardMsgID string) (*Msg, error)
api.Messages.SendFile(chatID string, fileName string, caption string, replyMsgID []string, forwardChatID string, forwardMsgID string) (*MsgLoadFile, error)
api.Messages.SendExistsVoice(chatID string, fileID string, replyMsgID []string, forwardChatID string, forwardMsgID string) (*Msg, error)
api.Messages.SendVoice(chatID string, fileName string, replyMsgID []string, forwardChatID string, forwardMsgID string) (*MsgLoadFile, error)
api.Messages.EditText(chatID string, text string, msgID string) (bool, error)
api.Messages.DeleteMessages(chatID string, msgIDs []string) (bool, error)
api.Chats.SendActions(chatID string, actions []ChatAction) (bool, error)
api.Chats.GetInfo(chatID string) (*Chat, error)
api.Chats.GetAdmins(chatID string) (*Admins, error)
api.Files.GetInfo(fileID string) (*FileInfo, error)

Типы можно увидеть в http://godoc.org/github.com/go-icq/icq

Пример

package main

import (
	"context"
	"log"
	"os"
	"time"

	"github.com/go-icq/icq"
)

func main() {
	// Инициализация
	b := icq.NewApi(os.Getenv("ICQ_TOKEN"), icq.ICQ) // or icq.Agent

	// Получение информации о боте
	log.Println(b.Self.Get())

	// Отправка сообщения
	resultSend, err := b.Messages.SendText("429950", "Привет!", nil, "", "")
	if err != nil {
		log.Fatal(err)
	}

	// Отправка файла
	resultFile, err := b.Messages.SendFile("429950", "./example/example.jpg", "коржик", []string{resultSend.MsgID}, "", "")
	if err != nil {
		log.Fatal(err)
	}

	// Отправка существующего файла по ID
	_, err = b.Messages.SendExistsFile("429950", resultFile.FileID, "Существующий файл", nil, "", "")
	if err != nil {
		log.Fatal(err)
	}

	// Редактирование сообщения
	_, err = b.Messages.EditText("429950", "Новый текст", resultSend.MsgID)
	if err != nil {
		log.Fatal(err)
	}

	// Будем слушать эвенты 5 минут. При закрытии контекста перестает работать цикл получения событий. В реальном мире контекст надо будет закрывать по сигналу ОС
	ctx, _ := context.WithTimeout(context.Background(), 5*time.Minute)
	for ev := range b.Events.Get(ctx) {
		switch ev := ev.(type) {
		case *icq.EventDataMessage:
			b.Messages.SendText(ev.Payload.Chat.ChatID, "Echo: "+ev.Payload.Text, []string{ev.Payload.MsgID}, "", "")
		default:
			log.Println(ev)
		}
	}
}

Автор

Александр NeonXP Кирюхин [email protected]

icq's People

Contributors

neonxp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

icq's Issues

Add mentions in ICQ

Please add mentions supported in icq messages.

Fix:
func (a *API) SendMessage(to string, message string, mentions []string) (*MessageResponse, error) {
a.mu.Lock()
defer a.mu.Unlock()
v := url.Values{
"aimsid": []string{a.token},
"r": []string{strconv.FormatInt(time.Now().Unix(), 10)},
"t": []string{to},
"message": []string{message},
"mentions": []string{strings.Join(mentions, ",")},
}
req, err := http.NewRequest(http.MethodGet, a.baseUrl+"/im/sendIM?"+v.Encode(), nil)
if err != nil {
return nil, err
}
resp, err := a.client.Do(req)
if err != nil {
return nil, err
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.