This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| case *linebot.TextMessage: | |
| // 預設訊息 | |
| reply := "msg ID:" + message.ID + ":" + "Get:" + message.Text + " , \n OK!" | |
| // 如果聊天機器人在群組中,開始儲存訊息。 | |
| if event.Source.GroupID != "" { | |
| // 先取得使用者 Display Name (也就是顯示的名稱) | |
| userName := event.Source.UserID |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.IO; | |
| using System.Linq; | |
| using System.Net; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using System.Net.Http; | |
| using System.Web; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 建立与数据库的连接 | |
| db, err := sql.Open("mysql", "user:password@tcp(host:port)/dbname") | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| defer db.Close() | |
| // 查询数据库 | |
| rows, err := db.Query("SELECT * FROM users") | |
| if err != nil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func buildFileName() string { | |
| return time.Now().Format("20060102150405") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for _, event := range events { | |
| if event.Type == linebot.EventTypeMessage { | |
| switch message := event.Message.(type) { | |
| ....... | |
| case *linebot.VideoMessage: | |
| //Get Video binary from LINE server based on message ID. | |
| content, err := bot.GetMessageContent(message.ID).Do() | |
| if err != nil { | |
| log.Println("Got GetMessageContent err:", err) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func newVideoFlexMsg(video, text string) linebot.FlexContainer { | |
| flex4 := 4 | |
| flex1 := 1 | |
| return &linebot.BubbleContainer{ | |
| Type: linebot.FlexContainerTypeBubble, | |
| Hero: &linebot.VideoComponent{ | |
| Type: linebot.FlexComponentTypeVideo, | |
| URL: video, | |
| PreviewURL: "https://scdn.line-apps.com/n/channel_devcenter/img/fx/01_1_cafe.png", | |
| AltContent: &linebot.ImageComponent{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Refer https://github.com/kkdai/linebot-video-gcp for more detail. | |
| // Must use "apiv1p1beta1" version to enable support on Chinese and MP3 | |
| speech "cloud.google.com/go/speech/apiv1p1beta1" //v1p1beta1 | |
| speechpb "google.golang.org/genproto/googleapis/cloud/speech/v1p1beta1" //v1p1beta1 | |
| func (c *ClientUploader) SpeachToText() (error, string) { | |
| ctx := context.Background() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var cl *storage.Client | |
| func UploadFileToGCS(file io.ReadCloser, object string) error { | |
| ctx := context.Background() | |
| ctx, cancel := context.WithTimeout(ctx, time.Second*50) | |
| defer cancel() | |
| // Upload an object with storage.Writer. | |
| wc := cl.Bucket(c.bucketName).Object(object).NewWriter(ctx) | |
| if _, err := io.Copy(wc, file); err != nil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func testGCP() err { | |
| client, err := storage.NewClient(context.Background()) | |
| if err != nil { | |
| fmt.Fatalf("Failed to create client: %v", err) | |
| return err | |
| } | |
| defer client.Close() | |
| fmt.Println("GCP connection succeessed!") | |
| return nil | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "cloud.google.com/go/storage" | |
| "context" | |
| "log" | |
| ) | |
| const ( | |
| projectID = "your-project-id" // FILL IN WITH YOURS |