Impossible to post special character into dialogflow query

I'm working on a dialgflow V1 bot. I'm really inspired by this repository : https://github.com/mlabouardy/dialogflow-angular5

I have an issue in my dialogflow service. I can't post query with special characters.

here is my diaogflow service working but when i pass my query it is code to utf-8 which broke dialogflow :

import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/Rx'
import { environment } from '../../environments/environment';

@Injectable()
export class DialogflowService {

  private baseURL: string = "https://api.dialogflow.com/v1/query?v=20170712";
  private token: string = environment.dialogFlowToken;

  constructor(private http: Http){}

  public getResponse(query: string){
    let data = {
      query : query,
      lang: 'fr',
      sessionId: '12345'
    }

    return this.http
      .post(`${this.baseURL}`, data, {headers: this.getHeaders()})
      .map(res => {
        return res.json()
      })
  }

  public getHeaders(){
    let headers = new Headers();
    headers.append('Authorization', `Bearer ${this.token}`);
    return headers;
  }
}

I tried to use :

  encode_utf8(s) {
    return unescape(encodeURIComponent(s));
  }

  decode_utf8(s) {
    return decodeURIComponent(escape(s));
  }

But it didn't work

Do you have a suggestion ? Thanks a lot. Romain

1 answer

  • answered 2018-11-20 13:20 Zot3x

    try to force it with additional header and see if that works.

    {'Content-Type' : 'application/json; charset=UTF-8'}