1
0
mirror of synced 2024-11-22 12:26:02 +03:00

improve translate, add markdowm formatting

This commit is contained in:
DmitryZagorulko 2018-09-24 17:31:31 +03:00
parent 4318e8c062
commit 52d3bfada6
2 changed files with 10 additions and 8 deletions

View File

@ -587,7 +587,7 @@ func mgWebhookHandler(c *gin.Context) {
var mb string var mb string
switch msg.Data.Type { switch msg.Data.Type {
case v1.MsgTypeProduct: case v1.MsgTypeProduct:
mb = fmt.Sprintf("%s\n", msg.Data.Product.Name) mb = fmt.Sprintf("*%s*\n", msg.Data.Product.Name)
if msg.Data.Product.Cost != nil && msg.Data.Product.Cost.Value != 0 { if msg.Data.Product.Cost != nil && msg.Data.Product.Cost.Value != 0 {
mb += fmt.Sprintf( mb += fmt.Sprintf(
@ -624,6 +624,8 @@ func mgWebhookHandler(c *gin.Context) {
m.ReplyToMessageID = qid m.ReplyToMessageID = qid
} }
m.ParseMode = "Markdown"
msgSend, err := bot.Send(m) msgSend, err := bot.Send(m)
if err != nil { if err != nil {
logger.Error(err) logger.Error(err)
@ -669,7 +671,7 @@ func mgWebhookHandler(c *gin.Context) {
} }
func getOrderMessage(dataOrder *v1.MessageDataOrder) string { func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
mb := getLocalizedMessage("order") mb := "*" + getLocalizedMessage("order")
if dataOrder.Number != "" { if dataOrder.Number != "" {
mb += " " + dataOrder.Number mb += " " + dataOrder.Number
@ -678,7 +680,7 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
if dataOrder.Date != "" { if dataOrder.Date != "" {
mb += fmt.Sprintf(" (%s)", dataOrder.Date) mb += fmt.Sprintf(" (%s)", dataOrder.Date)
} }
mb += "\n" mb += "*\n"
if len(dataOrder.Items) > 0 { if len(dataOrder.Items) > 0 {
mb += "\n" mb += "\n"
for k, v := range dataOrder.Items { for k, v := range dataOrder.Items {
@ -691,7 +693,7 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
if v.Quantity != nil { if v.Quantity != nil {
if v.Quantity.Value != 0 { if v.Quantity.Value != 0 {
mb += fmt.Sprintf( mb += fmt.Sprintf(
" %v", " _%v_",
v.Quantity.Value, v.Quantity.Value,
) )
} }
@ -700,7 +702,7 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
if v.Price != nil { if v.Price != nil {
if val, ok := currency[strings.ToLower(v.Price.Currency)]; ok { if val, ok := currency[strings.ToLower(v.Price.Currency)]; ok {
mb += fmt.Sprintf( mb += fmt.Sprintf(
" x %s\n", " _x %s_\n",
getLocalizedTemplateMessage( getLocalizedTemplateMessage(
"cost_currency", "cost_currency",
map[string]interface{}{ map[string]interface{}{
@ -719,7 +721,7 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
if dataOrder.Delivery != nil { if dataOrder.Delivery != nil {
if dataOrder.Delivery.Name != "" { if dataOrder.Delivery.Name != "" {
mb += fmt.Sprintf( mb += fmt.Sprintf(
"\n%s:\n%s", "\n*%s:*\n%s",
getLocalizedMessage("delivery"), getLocalizedMessage("delivery"),
dataOrder.Delivery.Name, dataOrder.Delivery.Name,
) )
@ -749,7 +751,7 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
if len(dataOrder.Payments) > 0 { if len(dataOrder.Payments) > 0 {
mb += fmt.Sprintf( mb += fmt.Sprintf(
"\n%s:\n", "\n*%s:*\n",
getLocalizedMessage("payment"), getLocalizedMessage("payment"),
) )
for _, v := range dataOrder.Payments { for _, v := range dataOrder.Payments {

View File

@ -48,4 +48,4 @@ order: "Order"
delivery: "Delivery" delivery: "Delivery"
payment: "Payment" payment: "Payment"
order_total: "Order total" order_total: "Order total"
cost_currency: "{{.Amount}} {{.Currency}}" cost_currency: "{{.Currency}}{{.Amount}}"