douyan4958 2018-01-30 18:43
浏览 132
已采纳

检查哪些用户将表情符号发送到电报机器人

I need to check what user send a word, not a audio, video, sticker or emoji, so I try to create if statement but I don't know how to check if user send emoji to bot.

if reflect.TypeOf(update.Message.Text).Kind() == reflect.String && update.Message.Text != "" //Check if message from user is not emoji {    
    msg := tgbotapi.NewMessage(update.Message.Chat.ID, "It's a Text")    
    bot.Send(msg)
} else {
    msg := tgbotapi.NewMessage(update.Message.Chat.ID, "It's a not Text")    
    bot.Send(msg)
}

Full code:

package main

import (
    "encoding/json"
    "io/ioutil"
    "log"
    "net/http"
    "reflect"
    "runtime"
    "strings"    
    "github.com/Syfaro/telegram-bot-api"
)

func telegramBot() {    
    //Create bot
    bot, err := tgbotapi.NewBotAPI("TOKEN")
    if err != nil {
        log.Panic(err)
    }    
    //Check if bot autorized
    bot.Debug = true
    log.Printf("Autorized on account %s", bot.Self.UserName)

    //Set update timeout
    u := tgbotapi.NewUpdate(0)
    u.Timeout = 60

    //Get updates from bot
    updates, err := bot.GetUpdatesChan(u)

    for update := range updates {
        if update.Message == nil {
            continue
        }    
        if reflect.TypeOf(update.Message.Text).Kind() == reflect.String && update.Message.Text != "" {              
                //Create search url
                url := update.Message.Text
                request := "https://en.wikipedia.org/w/api.php?action=opensearch&search=" + url + "&limit=1&origin=*&format=json"   
            //Check from who was arrived message and send to him answer from wikipedia
            msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Message to user")    
            //Send message
            bot.Send(msg)
        } else {
            msg := tgbotapi.NewMessage(update.Message.Chat.ID, "It's not a Text")    
            //Send message
            bot.Send(msg)
        }
    }
}

func main() {    
    //Set maximum cpu cores to use
    num := runtime.NumCPU()
    runtime.GOMAXPROCS(num)    
    //Call Bot
    telegramBot()
}

So I need to response user only if he send bot string with word, not an audio, video, sticker or emoji.

  • 写回答

1条回答 默认 最新

  • douren0558 2018-02-24 12:09
    关注

    So I don't find answer and left this if statement:

    if reflect.TypeOf(update.Message.Text).Kind() == reflect.String && update.Message.Text != ""
    

    He check if message from user is text not a audio, video, sticker but emoji is text so thay pass it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛